XF 2.0 Include vs Macro?

Jaxel

Well-known member
If I'm only ever going to call a template macro once... what advantage would there be to use a macro instead of just using an include? With includes, you don't have to specify variable arguments.
 
As you surmised, if a macro is only gonna be called once there's little benefit, outside of possibly letting other mods that interface with your mod call the macro.

The only real benefit would be to avoid variable poisoning. Essentially, if you have a macro, it's like calling a function in PHP (and that's largely what happens when the template is compiled, but I digress); variables defined inside a macro do not affect the HTML surrounding it.

How useful that would be to you, that's another matter entirely.


Fillip
 
We generally prefer macros specifically because they define what variables they need/support. There were plenty of times in XF1 where some magic behavior happened for unclear reasons because a variable was passed into an include implicitly.
 
Back
Top Bottom