-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Phil Sturgeon's Template Library
NOTICE: This information was really out of date and confusing. More up-to-date documentation can be found here: http://philsturgeon.co.uk/demos/codeigniter-template/user_guide/.
In case the above link to the user guide is broken, its included with the source code. Just download the source from https://github.com/philsturgeon/codeigniter-template and check the user_guide folder.
In this example, we will use a module called site
that contains a controller start.php
. This controller has a method about()
which will show a view. Read the comments in the code for details.
//file: modules/site/start.php <?php class Start extends MX_Controller { function about(){ //nice to be able to set title right in the controller in one shot. //Before using template, I had to keep passing the title value here and //there till it reached the header where finally it could get echoed. $this->template->title('about this site'); //'default_theme' is a folder name. $this->template->set_theme('default_theme'); //This layout file can use $template['variables'] to put your contents $this->template->set_layout('one_col'); //setting partials view. see the image above for header.php and footer.php locations. //these will be available in layout file as $template['partials']['header'] and //$template['partials']['footer'] $this->template->set_partial('header','blocks/header'); $this->template->set_partial('footer','blocks/footer'); //the main content view that contains about page's content. //this will be available in layout file as $template['body'] $this->template->build('start_about_view'); }... }
The layout file will use the template array to get the values.
<?php //file themes/default_theme/views/layouts/one_col.php echo $template['partials']['header']; echo $template['body']; echo $template['partials']['footer']; //eof
Below is the content for about page.
<!--file modules/site/views/start_about_view.php -> <div class="container"> <p>about page start_about_view</p> <p>about page start_about_view</p> <p>about page start_about_view</p> <p>about page start_about_view</p> <p>about page start_about_view</p> <p>about page start_about_view</p> <p>about page start_about_view</p> <p>about page start_about_view</p> <p>about page start_about_view</p> <p>about page start_about_view</p> <p>about page start_about_view</p> <p>about page start_about_view</p> <p>about page start_about_view</p> <p>about page start_about_view</p> </div>
Likewise make your header.php
and footer.php
in modules/site/views/blocks/header.php
and modules/site/views/blocks/footer.php
. check the image above.
** In the header.php don't forget to echo $template['title']
.
The output will look like this .. don't mind the complicated looking header and footer I have got in the picture.
Good Luck.