add registerPartial to fix #10

This commit is contained in:
fzerorubigd 2013-06-01 17:55:42 +04:30
parent 65eb09d101
commit ed925cf1b8
No known key found for this signature in database
GPG Key ID: D6EE858AF9D2999A

View File

@ -73,6 +73,7 @@ class Handlebars_Engine
'UTF-8'
);
private $_aliases = array();
/**
* Handlebars engine constructor
* $options array can contain :
@ -117,6 +118,12 @@ class Handlebars_Engine
}
$this->_escapeArgs = $options['escapeArgs'];
}
if (isset($options['partials_alias'])
&& is_array($options['partials_alias'])
) {
$this->_aliases = $options['partials_alias'];
}
}
@ -413,11 +420,40 @@ class Handlebars_Engine
*/
public function loadPartial($name)
{
if (isset($this->_aliases[$name])) {
$name = $this->_aliases[$name];
}
$source = $this->getPartialsLoader()->load($name);
$tree = $this->_tokenize($source);
return new Handlebars_Template($this, $tree, $source);
}
/**
* Register partial alias
*
* @param string $alias Partial alias
* @param string $content The real value
*
* @return void
*/
public function registerPartial($alias, $content)
{
$this->_aliases[$alias] = $content;
}
/**
* Un-register partial alias
*
* @param string $alias Partial alias
*
* @return void
*/
public function unRegisterPartial($alias)
{
if (isset($this->_aliases[$alias])) {
unset($this->_aliases[$alias]);
}
}
/**
* Load string into a template object