move template conversion to render, to allow people to dynamically change _template variable
This commit is contained in:
parent
79d9633705
commit
3c74063551
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue