-
Notifications
You must be signed in to change notification settings - Fork 8
v1.5 The new template and layout system.
Since Fuel Start 1.5.6, we use new layout system from the original that has only 'the page template' and 'content template'.
To make it easier for you to understand what 'the page template' and 'content template' is, lets see this picture.
The blue area is 'the page template' which is whole page template. It is start from <!doctype>
until </html>
When you call generatePage()
, Fuel Start will get the 'content template' to load view and put in $output['page_content']
variable which will be echo as $page_content
variable in 'the page template'. 'The page template' will be load after 'content template' was loaded
For more details about ``generatePage()` in frontend controller and admin controller, please click on the link to read more details.
Now i will assume that you understand about basic template system which has 'the page template' and 'content template'.
Since v.1.5.6, before you call to generatePage()
you can call to generateLayoutAndPage()
to generate layout of the 'content template' and then generate page from 'the page template' immediately. Or you can call to generateLayout()
to generate layout many time as you want and then call generatePage()
.
Lets see screenshots. This is generated layout 1 column of the 'content template'
This is generated layout 2 column
This is layout 1 column inside layout 2 column or generate layout multiple times.
generateLayout()
Third attributes refer from FuelPHP's theme view()
method.
$view
can be 'content template' file if generate layout once, or it can be second layout file (please check at test controller action_1inside2column method).
$layout
is layout file name. The layout file must place in public/themes/<theme name>
/(front or admin)/layout/
You can call generateLayout()
many times to create multiple layout inside another layout.
If you use this method, you must call generatePage()
to generate page from 'the page template'.
example:
public function action_1inside2column()
{
$output['name'] = 'FuelStart';
// <head> output ---------------------------------------------------------------------
$output['page_title'] = $this->generateTitle('Test');
// <head> output ---------------------------------------------------------------------
// generate first sub layout. ---------------------------------------------------------
$layout = $this->generateLayout('front/templates/test/index_v', $output, false, '1column');
$output = array_merge($output, $layout);
$layout_file = 'front/templates/test/index_v';
if (isset($layout['layout_file'])) {
$layout_file = $layout['layout_file'];
}
unset($layout);
// generate second sub layout -------------------------------------------------------
$layout = $this->generateLayout($layout_file, $output, false, '2column');
$output = array_merge($output, $layout);
$layout_file = 'front/templates/test/index_v';
if (isset($layout['layout_file'])) {
$layout_file = $layout['layout_file'];
}
unset($layout);
return $this->generatePage($layout_file, $output, false);
}// action_1inside2column
generateLayoutAndPage()
Third attributes refer from FuelPHP's theme view()
method.
$view
can be 'content template' file if generate layout once, or it can be second layout file (please check at test controller action_1inside2column method).
$layout
is layout file name. The layout file must place in public/themes/<theme name>
/(front or admin)/layout/
This method will be generate layout once and then call to generatePage()
immediately.
If you use this method, you have not to call generatePage()
again.
example:
public function action_2column()
{
$output['name'] = 'FuelStart';
// <head> output ---------------------------------------------------------------------
$output['page_title'] = $this->generateTitle('Test');
// <head> output ---------------------------------------------------------------------
return $this->generateLayoutAndPage('front/templates/test/index_v', $output, false, '2column');
}// action_2column
The layout file must put this code to render 'the content template' into it properly.
<?php
if (isset($layout_content)) {
echo $layout_content;
}
?>