• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Passing simple variable to template

Marcus

Well-known member
#1
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;
}
}
}
 

Jake Bunce

XenForo moderator
Staff member
#2
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.
 

Marcus

Well-known member
#3
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.
 

Marcus

Well-known member
#4
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 :)