Skip to content
Browse files

Added layout function to templates

  • Loading branch information...
1 parent df0ba05 commit f6766cb9517481a5297b0d70bdbd65563e9ff890 @brucespang committed
Showing with 22 additions and 2 deletions.
  1. +19 −2 frank/core.php
  2. +3 −0 frank/settings.php
View
21 frank/core.php
@@ -163,7 +163,7 @@ public static function render_template($name, $options){
ob_start();
call_user_func($template, $locals);
- self::$body .= ob_get_contents();
+ $result = ob_get_contents();
ob_end_clean();
}elseif(file_exists($view_path.'/'.$name)){
@@ -172,9 +172,26 @@ public static function render_template($name, $options){
ob_start();
$template($view_path.'/'.$name, $locals);
- self::$body .= ob_get_contents();
+ $result = ob_get_contents();
ob_end_clean();
}
+
+ if(isset($options['layout']) || settings::get('layout') !== false){
+ $layout = create_function('$path,$yield', 'require($path);');
+
+ if(isset($options['layout']))
+ $file = $view_path.'/'.$options['layout'];
+ else
+ $file = $view_path.'/'.settings::get('layout');
+
+ ob_start();
+ $layout($file, $result);
+ $result = ob_get_contents();
+ ob_end_clean();
+ }
+
+ self::$body .= $result;
+
}
/**
View
3 frank/settings.php
@@ -26,6 +26,9 @@ function set($setting_name, $value){
* @return string Value of the setting
*/
function get($setting_name){
+ if(!isset(self::$settings[$setting_name]))
+ return false;
+
if(gettype(self::$settings[$setting_name]) == 'object')
$value = call_user_func(self::$settings[$setting_name]);
else

0 comments on commit f6766cb

Please sign in to comment.
Something went wrong with that request. Please try again.