move template conversion to render, to allow people to dynamically change _template variable

This commit is contained in:
Jeremy Bush 2010-08-09 08:46:45 -05:00
parent 79d9633705
commit 3c74063551
2 changed files with 19 additions and 28 deletions

View file

@ -42,25 +42,6 @@ class Kohana_Kostache extends Mustache
parent::__construct($template, $view, $partials);
$this->_charset = Kohana::$charset;
// Override the template location to match kohana's conventions
if ( ! $this->_template)
{
$foo = explode('_', get_class($this));
array_shift($foo);
$view_location = strtolower(implode('/', $foo));
}
else
{
$view_location = $this->_template;
}
$template = Kohana::find_file('templates', $view_location, 'mustache');
if ($template)
$this->_template = file_get_contents($template);
else
throw new Kohana_Exception('Template file not found: templates/'.$view_location);
}
/**
@ -138,6 +119,25 @@ class Kohana_Kostache extends Mustache
public function render($template = null, $view = null, $partials = null)
{
// Override the template location to match kohana's conventions
if ( ! $this->_template)
{
$foo = explode('_', get_class($this));
array_shift($foo);
$view_location = strtolower(implode('/', $foo));
}
else
{
$view_location = $this->_template;
}
$template = Kohana::find_file('templates', $view_location, 'mustache');
if ($template)
$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)
{

View file

@ -14,19 +14,10 @@ class View_Kohana_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' => $view_location
);
// Make the layout view the child class's template
$this->_template = file_get_contents(Kohana::find_file('templates', $this->_layout, 'mustache'));
return parent::render($template, $view, $partials);
}