⭐ Alex ⭐
Well-known member
There is an array that I use throughout templates and it would seem reasonable to use a macro to store it as the documentation states: "use a macro any place you want to produce the same thing multiple times in multiple different files".
I would like to then be able to pass it to a callback.
Here's what I tried:
A template called my_macro
Another template:
But I get an error logged:
So I supposed $static_data isn't set and it's null.
I kind of realize macros are probably used to emit HTML. But I can't say I've grasped template processing enough to conclude that content emitted by macros doesn't get a pass by the template syntax parser. But again, my code would have to then be modified to emit xf:set var instead of it being processed within the macro.
I think the better question is, can xf:set create a global variable.
I would like to then be able to pass it to a callback.
Here's what I tried:
A template called my_macro
HTML:
<xf:macro name="get_static_data">
<xf:set var="$static_data" value="{{ [1, 2, 4, 4] }}"></xf:set>
</xf:macro>
Another template:
HTML:
<xf:macro template="my_macro" name="get_static_data" />
<xf:callback class="Addon\MyCallback" method="getHTML" params="{$static_data}"></xf:callback>
But I get an error logged:
Argument 4 passed to XF\Template\Templater::callback() must be of the type array, null given
So I supposed $static_data isn't set and it's null.
I kind of realize macros are probably used to emit HTML. But I can't say I've grasped template processing enough to conclude that content emitted by macros doesn't get a pass by the template syntax parser. But again, my code would have to then be modified to emit xf:set var instead of it being processed within the macro.
I think the better question is, can xf:set create a global variable.
Last edited: