Hello everyone,
I have recently been in quick-fire blogging mode. After playing with the superb template library developed by Phil Sturgeon.
The following template helper is the outcome of tweaking that makes life easier while setting up view partials and calling them inside the layout dynamically. The helper also has an add-on use which gives user the option to use region specific partial loading.
Controller:
welcome.php
$partial_list[]['region'] = 'left';
$partial_list[]['name'] = 'category';
$partial_list[]['view'] = 'partial_category';
$partial_list[]['region'] = 'right';
$partial_list[]['name'] = 'login_box';
$partial_list[]['view'] = 'partial_login';
/* following functionautomatically sets the partials
* based on the above array and also passes $partial_list
* variable to the view.
*/
/*
* make sure the pareser helper is loaded before
* calling this function
*/
setup_partials($partial_list);
$this->template->set_layout('home_layout');
$this->template->build('home_view');
Layout:
home_view.php
<html>
<head>
<title><?php echo $template['title'];?></title>
</head>
<body>
<div class="left">
/* Will show only partials with region set as left */
<?php show_partials('list', 'left', $partial_list, $template); ?>
</div>
<div class="mid"><?php echo $template['body'];?></div>
<div class="right">
/* Will show only partials with region set as right */
<?php show_partials('list', 'right', $partial_list, $template);?>
</div>
</body>
</html>
Detail about the usage can be found in the actual helper file, also feel free to comment here and I will try my best to help out.
Download Helper:
DOWNLOAD PARSER HELPER
thanks,
faisal ahmed
web application developer
web: http://www.faisalbd.com/
email: thephpx(at)gmail(dot)com