Add the possibility to attach template hooks with local variables

This commit is contained in:
Frederic Guillot
2016-08-13 18:08:46 -04:00
parent ffe61abc69
commit 2ebe8b3272
4 changed files with 57 additions and 17 deletions

View File

@@ -24,8 +24,8 @@ class HookHelper extends Base
{
$buffer = '';
foreach ($this->hook->getListeners($hook) as $file) {
$buffer .= $this->helper->asset->$type($file);
foreach ($this->hook->getListeners($hook) as $params) {
$buffer .= $this->helper->asset->$type($params['template']);
}
return $buffer;
@@ -43,8 +43,12 @@ class HookHelper extends Base
{
$buffer = '';
foreach ($this->hook->getListeners($hook) as $template) {
$buffer .= $this->template->render($template, $variables);
foreach ($this->hook->getListeners($hook) as $params) {
if (! empty($params['variables'])) {
$variables = array_merge($variables, $params['variables']);
}
$buffer .= $this->template->render($params['template'], $variables);
}
return $buffer;
@@ -54,13 +58,18 @@ class HookHelper extends Base
* Attach a template to a hook
*
* @access public
* @param string $hook
* @param string $template
* @param string $hook
* @param string $template
* @param array $variables
* @return $this
*/
public function attach($hook, $template)
public function attach($hook, $template, array $variables = array())
{
$this->hook->on($hook, $template);
$this->hook->on($hook, array(
'template' => $template,
'variables' => $variables,
));
return $this;
}
}