Template Syntax: XenForo Tags

Unmaintained Template Syntax: XenForo Tags

DEPRECATED
The xen:hook tag has been deprecated in XenForo 1.2 and beyond, this limited documentation exists only to explain the purpose of the tag.

This tag was designed to work in conjunction with listeners and add-ons, but provided no direct HTML translation. It was used to allow add-ons to intercept compilation of a template and inject their add-ons code in to avoid template edits for end users. This system has been replaced with Template Modifications. If you would like to read more about template modifications, I highly suggest you read the following:
As of XenForo 1.2 RC3, the Template Modifications system is being hidden unless you are in debug mode, as with all other add-on development tools.
The xen:comment tag is used to create comments within a template, similar to how the HTML comment works. However, unlike the HTML equivalent, The xen:comment tag and anything within it will be removed upon compilation.

Attributes
The xen:comment tag takes no attributes.

Example
HTML:
<xen:comment>This little code is used to say hi.</xen:comment>
<!-- HI! -->

The above will output the following:
HTML:
<!-- HI! -->

Developer Note: This tag is does not have a corresponding class like the other tags. This is handled via the lexer / parser directly.
The xen:untreated tag is used to turn off the lexer / parser within it, meaning no xen:tags, properties, or template helpers will be compiled into plain HTML and will be displayed as is. As of 1.2 RC2, this tag is not used within the XenForo code base.

Attributes
The xen:untreated tag takes no attributes.

Example
Code:
<xen:untreated><script>
var example = '<xen:if is="1">true<xen:else />false</xen:if>';
alert(example);
</script></xen:untreated>
<script>
var example = '<xen:if is="1">true<xen:else />false</xen:if>';
alert(example);
</script>
The above example has two simple scripts that each alert the user with some text. For the untreated script, the alert will contain:
<xen:if is="1">true<xen:else />false</xen:if>

For the treated script (the second one), the output will be "true" since 1 is a truthy value.

Developer Note: This tag is does not have a corresponding class like the other tags. This is handled via the lexer / parser directly.
The xen:foreach tag is used as a simple iterator. It is used to programmatically repeat blocks of code and using different data upon each iteration. This simplifies add-on development and reduces the number of templates by containing this repetition within a single template. The xen:foreach tag is internally converted to the PHP foreach control structure.

Attributes
The xen:foreach tag will take the following attributes:
  • loop (required)
    • The loop attribute is used to define the data set that you are working over. Most likely, this will be an array.
  • value (required)
    • The value attribute is the variable name you would like to map each value to during its iteration. This will be used within the xen:foreach tag to populate data.
  • key
    • If you have a key => value pair in your data source (ie, id => name) and need to access the key within the xen:foreach, the key attribute will define the mapped variable, as the value attribute did.
  • i
    • The i attribute allows you to map which iteration you are on to a variable within each iteration. This begins at 1 and increases by 1 on each iteration.
  • count
    • The count attribute will assign the total number of iterations to a variable for use within the xen:foreach.
Example
Data:
Code:
$navigation = array(
  array('href'=>'#', 'value'=>'first'),
  array('href'=>'#', 'value'=>'second'),
  array('href'=>'#', 'value'=>'third'),
);
Code:
                <xen:foreach loop="$navigation" value="$breadcrumb" i="$i" count="$count" key="$key">
                    <span>Total breadcrumb elements: {$count}</span>
                    <span class="crust iteration_{$i} breadcrumb_{$key}">
                        <a href="{$breadcrumb.href}" class="crumb"><span>{$breadcrumb.value}</span></a>
                        <span class="arrow"><span>&gt;</span></span>
                    </span>
                </xen:foreach>

The above example is both a simplified and expanded version of how XenForo builds breadcrumbs. In this example, $key will be one less than $i, since arrays in PHP are auto-indexed starting at 0. Since $navigation contains 3 items, $count would equal 3. The output will be as follows:
Code:
                    <span>Total breadcrumb elements: 3</span>
                    <span class="crust iteration_1 breadcrumb_0">
                        <a href="#" class="crumb"><span>first</span></a>
                        <span class="arrow"><span>&gt;</span></span>
                    </span>
                    <span>Total breadcrumb elements: 3</span>
                    <span class="crust iteration_2 breadcrumb_1">
                        <a href="#" class="crumb"><span>second</span></a>
                        <span class="arrow"><span>&gt;</span></span>
                    </span>
                    <span>Total breadcrumb elements: 3</span>
                    <span class="crust iteration_3 breadcrumb_2">
                        <a href="#" class="crumb"><span>third</span></a>
                        <span class="arrow"><span>&gt;</span></span>
                    </span>
Top Bottom