Skip to content

Commit

Permalink
Multi view rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
Owen Richards committed Feb 28, 2015
1 parent 7df7612 commit b8f426c
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions application/core/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,32 @@ public function render($filename, $data = null)
require Config::get('PATH_VIEW') . '_templates/footer.php';
}

/**
* Similar to render, but accepts an array of separate views to render between the header and footer. Use like
* the following: $this->view->renderMulti(array('help/index', 'help/banner'));
* @param array $filenames Array of the paths of the to-be-rendered view, usually folder/file(.php) for each
* @param array $data Data to be used in the view
*/
public function renderMulti($filenames, $data = null)
{
if(!is_array($filenames)) {
self::render($filenames, $data);
return false;
}

if ($data) {
foreach ($data as $key => $value) {
$this->{$key} = $value;
}
}

require Config::get('PATH_VIEW') . '_templates/header.php';
foreach($filenames as $filename) {
require Config::get('PATH_VIEW') . $filename . '.php';
}
require Config::get('PATH_VIEW') . '_templates/footer.php';
}

/**
* Same like render(), but does not include header and footer
* @param string $filename Path of the to-be-rendered view, usually folder/file(.php)
Expand Down

0 comments on commit b8f426c

Please sign in to comment.