A useful function is being able to pass variables from a template to the container, so they are available globally.
Take the thread ID for example, that typically isn't available outside the
thread_view
template.
We can make it available elsewhere by adding this to the
thread_view
template:
HTML:
<xf:page option="threadID">{$thread.thread_id}</xf:page>
What that code does is take the thread ID value from
$thread.thread_id
and assign it to a new variable called
threadID
.
You can name the option value whatever you want but ensure it does not clash with an existing variable.
That then makes it possible to call the thread ID in the
PAGE_CONTAINER
template using the option value as the var, which in this case is
{$threadID}
.
Expanding on that, conditional statements can be used to target a specific thread:
HTML:
<xf:if is="$threadID == 2">
Content for thread 2 only
</xf:if>
Or multiple threads:
HTML:
<xf:if is="in_array($threadID, [2,8,20])">
Content for threads 2, 8, and 20
</xf:if>
Where this really becomes useful though is in ad templates.
The thread ID can be utilised using
$__globals.threadID
.
Which allows you to target specific threads with different ads using a single ad template like this:
HTML:
<xf:if is="$__globals.threadID == 2">
Content for thread 2
</xf:if>
<xf:if is="$__globals.threadID == 8">
Content for thread 8
</xf:if>
Or this:
HTML:
<xf:if is="$__globals.threadID == 2">
Content for thread 2
<xf:elseif is="$__globals.threadID == 8" />
Content for thread 8
<xf:else />
Content for other threads
</xf:if>