Conditional Statements

Conditional Statements


XenForo moderator
Staff member
Brogan submitted a new resource:

Conditional Statements - Guide and tutorial for conditional statements using XenForo syntax


The following conditional statements will only work in templates which support the arguments and parameters.

Statements can be expanded using AND, OR, and <xen:else />.

Replacing == with != in the following examples will change the condition from true to false.
For example, <xen:if is="{$visitor.user_id} == x"> for true, <xen:if is="{$visitor.user_id}...
Read more about this resource...


Well-known member
Thank you for posting this as a resource. I hunt down your FAQ thread just to jump to the conditional statements tutorial at least once a month cause something always comes up to where I'll need it. I even bookmarked that thread at one point. Posting this as a resource will make this a lot easier to find, thank you.


Well-known member
What is the meaning of the percentage in this conditional:
<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == x AND !{$message.conversation_id}">
This content will show after post x on every page in a thread
Is it the modulus operator or something else ?
Thanks for this resource, @Brogan. If I only wanted to show a button to a user on their own personal details page (it's going to be an edit button), how do I condition everyone out except for the user?


XenForo moderator
Staff member
Brogan updated Conditional Statements with a new update entry:

Making the category ID available for use in the ad_ templates

If you have pages set for categories (ACP -> Options -> Node & Forum List) you may want to utilise the category ID in the ad_ templates, to prevent ad's being shown in certain categories for example.

To do so, edit the category_view template and add the following at the top:
<xen:container var="$category.node_id">{$category.node_id}</xen:container>
That will ensure the category ID is available for use in the ad_ templates, allowing you to use the category node ID conditional as...
Read the rest of this update entry...


Well-known member
I would like to show content under the sticky post but only on the first page of a forum.

Anybody know how do I prevent the content from showing on page 2, 3 etc.?


XenForo moderator
Staff member
How many sticky threads do you have?

Most forums usually only have a few so the ad_thread_list_below_stickies will work for that.