Fixed In the templater_macro_pre_render event, the value passed to $globalVars isn't necessarily the value that winds up in $__globals

Jeremy P

XenForo developer
Staff member
Affected version
2.0.0 RC1
Per the title, the value that gets passed to the template_macro_pre_render event as $globalVars isn't always the value that winds up as $__globals in the macro. As far as I can tell, this can happen during macro nesting because of code in XF\Template\Templater::setupBaseParamsForMacro().

What is passed to the event as $globalVars is actually passed to that method as $parentVars, and the resulting value of $__globals in the macro depends on whether or not a __globals sub-array is present (which can vary depending on how the macro was called).

Because of this, I've had to include the following boilerplate in all of my template_macro_pre_render events to make sure the value is actually available in the macro:
PHP:
if (isset($globalVars['__globals'])) {
    $__globals = &$globalVars['__globals'];
} else {
    $__globals = &$globalVars;
}
$__globals['key'] = "value";

Any chance at changing the behavior here so the boilerplate isn't necessary?
 
Given the docs of this, I've pulled out __globals if available before this event fires, so the boilerplate shouldn't be necessary any longer.
 
Back
Top Bottom