Passing simple variable to template

Marcus

Well-known member
I want to pass a simple variable $testVar to a template but {$testVar} does not work in both templates my_header, body. Here is my code:


public static function templateHook($hookName, &$contents, array $hookParams, XenForo_Template_Abstract $template)
{
switch($hookName)
{
case 'body':
{
$myParams = array(
'testVar' => 'test',
);

$contents = $template->create('my_header', array_merge($myParams, $template->getParams())) . $contents;
break;
}
}
}
 
I tested your code and it works.

There must be something else causing the problem. Maybe another listener. Or maybe you are working with the wrong style.
 
Thanks you very much for even testing the code! I am looking into this and will report here where the problem was. Maybe another coder then can read this if he experiences the same.
 
For the record, I just tried this one more time and now it works. I don't know why it didn't work in the first place :)
 
Top Bottom