Moving partial processing to render, so that people can add to them after construct

This commit is contained in:
Jeremy Bush 2010-08-04 14:20:33 -05:00
parent c60b276d26
commit 23f063f3a9
2 changed files with 18 additions and 12 deletions

View file

@ -61,15 +61,6 @@ class Kohana_Kostache extends Mustache
$this->_template = file_get_contents($template);
else
throw new Kohana_Exception('Template file not found: templates/'.$view_location);
// Convert partials to expanded template strings
foreach ($this->_partials as $key => $partial_template)
{
if ($location = Kohana::find_file('templates', $partial_template, 'mustache'))
{
$this->_partials[$key] = file_get_contents($location);
}
}
}
/**
@ -144,4 +135,18 @@ class Kohana_Kostache extends Mustache
return '';
}
}
public function render($template = null, $view = null, $partials = null)
{
// Convert partials to expanded template strings
foreach ($this->_partials as $key => $partial_template)
{
if ($location = Kohana::find_file('templates', $partial_template, 'mustache'))
{
$this->_partials[$key] = file_get_contents($location);
}
}
return parent::render($template, $view, $partials);
}
}

View file

@ -2,7 +2,7 @@
class View_Layout extends Kostache
{
const LAYOUT = 'layout';
protected $_layout = 'layout';
/**
* @var string template title
@ -15,16 +15,17 @@ class View_Layout extends Kostache
public function render($template = null, $view = null, $partials = null)
{
// Turn the child template into a partial
// This should change, because if the child changes the template name to a non-standard name, this breaks
$foo = explode('_', get_class($this));
array_shift($foo);
$view_location = strtolower(implode('/', $foo));
$this->_partials+=array(
'body' => file_get_contents(Kohana::find_file('templates', $view_location, 'mustache'))
'body' => $view_location
);
// Make the layout view the child class's template
$this->_template = file_get_contents(Kohana::find_file('templates', self::LAYOUT, 'mustache'));
$this->_template = file_get_contents(Kohana::find_file('templates', $this->_layout, 'mustache'));
return parent::render($template, $view, $partials);
}