Macros aren't difficult - you can think of them as isolated sub-templates.
Developer documentation for XenForo
xenforo.com
Let's assume you've got an array of links like this
PHP:
$links = [
[
'title' => 'Some cool url title'
'url' => 'https://coolsite.com',
],
[
'title' => 'Another cool url title'
'url' => 'https://anothersie.com',
],
];
and you want to output those links in a template.
There would be 3 ways to do this
Hardcoded loop within the template
maintemplate
Code:
<ul>
<xf:foreach from="$links" value="$link">
<li><a href="{$link.url}">{$link.title}</a></li>
</xf:foreach>
</ul>
This is easy and works perfectly fine if this is the only place where you need this output - if you need it in multiple places you would have to duplicate code (which should be avoided)
Using a include template
maintemplate
Code:
<ul>
<xf:foreach from="$links" value="$link">
<xf:include template="linkbittemplate" />
</xf:foreach>
</ul>
linkbittemplate
Code:
<li><a href="{$link.url}">{$link.title}</a></li>
This allows for code reuse, eg.
linkbittemplate
can be included from various templates.
But now you have saparated things and if there are many such snippets it will become chaotic quickly.
Also as the included template uses the variables from the parent scope if can only be used if the names are idempotent and you have to be careful not to created unwanted side-effects (like modifying variables from the
parent)
Having many templates also has a (theoretical, probably hardly even measureable) negative runtime performance impact.
Using a macro
maintemplate
Code:
<ul>
<xf:foreach from="$links" value="$link">
<xf:macro id="link" arg-link="{$link}" />
</xf:foreach>
</ul>
<xf:macro id="link" arg-link="!">
<li><a href="{$link.url}">{$link.title}</a></li>
</xf:macro>
This way we've got only one template but also a reusable, isolated part which can be used from within the template and from other templates.
othertemplate
Code:
Here are our Top Links<br />
<br />
<ol>
<xf:foreach from="$topLinks" value="$topLink">
<xf:macro id="maintemplate::link" arg-link="{$topLink}" />
</xf:foreach>
</ul>
As you can see, this other template use a different variable (
$topLink
) but passes this as argument name
link
(arg-link) to the macro where it can be used just as a "normal" template variable would be used - but isolated to this macro.
No explanation of arg-type, arg-group, etc.. I need to know what arg-onlyInclude and arg-additionalFilters does, what values they expect (string? array?)
See above, those are just the arguments for the macro - the valid types depend on the macro.
Anyone have any luck? I have multiple fields in each group and I'm trying to specify a single field within that group for both edit and display.
You may need to explain more what exactly you are trying to do - at least I don't understand your question without further explanation