I am new here in pw and I think a template approach with output buffering is very useful. I use yii for other projects and want to use a cms too for some projects. Templating with output buffer is done in yii and other frameworks. The big advantage is that you can write clear template files with html and php echos since php 5.4 always with the short echo tags. The performance of output buffering in php is also very good.
The simplest way to do this: _init.php (The prepended config file)
<?php
/**
* The prepended file for all template files
*
* It buffers the output and after rendering all outputs and view Files the buffer will keep in the $content variable
* and this content variable will decorated by the main layout file.
*/
ob_start();
ob_implicit_flush(false);
/**
* Renders a view file as a PHP script.
*
* This method treats the view file as a PHP script and includes the file.
* It extracts the given parameters and makes them available in the view file.
*
* @params string $viewFile the view file.
* @param array $params the parameters (name-value pairs) that will be extracted and made available in the view file.
* @return void
*/
function render($viewFile, $params = [])
{
extract($params, EXTR_OVERWRITE);
require('views/' . $viewFile . '.php');
}
_out.php (the appended template file)
<?php
/*
* Now the content is complete and we can output the content
* with the decorated layout file.
*/
$content = ob_get_clean();
include('layouts/main.php');