Added missing template detection when using "new View_Foo" instead of "Kostache::factory(foo)"
This commit is contained in:
parent
e655f3812b
commit
58c26155ee
|
@ -56,8 +56,14 @@ abstract class Kohana_Kostache {
|
||||||
* @uses Kostache::template
|
* @uses Kostache::template
|
||||||
* @uses Kostache::partial
|
* @uses Kostache::partial
|
||||||
*/
|
*/
|
||||||
public function __construct($template, array $partials = NULL)
|
public function __construct($template = NULL, array $partials = NULL)
|
||||||
{
|
{
|
||||||
|
if ( ! $template)
|
||||||
|
{
|
||||||
|
// Detect the template for this class
|
||||||
|
$template = $this->_detect_template();
|
||||||
|
}
|
||||||
|
|
||||||
// Load the template
|
// Load the template
|
||||||
$this->template($template);
|
$this->template($template);
|
||||||
|
|
||||||
|
@ -233,4 +239,23 @@ abstract class Kohana_Kostache {
|
||||||
return file_get_contents($file);
|
return file_get_contents($file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detect the template name from the class name.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function _detect_template()
|
||||||
|
{
|
||||||
|
// Start creating the template path from the class name
|
||||||
|
$template = explode('_', get_class($this));
|
||||||
|
|
||||||
|
// Remove "View" prefix
|
||||||
|
array_shift($template);
|
||||||
|
|
||||||
|
// Convert name parts into a path
|
||||||
|
$template = strtolower(implode('/', $template));
|
||||||
|
|
||||||
|
return $template;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue