Conditional Statements for XenForo 2

Conditional Statements for XenForo 2

eTiKeT™

Well-known member
eTiKeT™ submitted a new resource:

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

Conditional Statements for XenForo 2
The conditional statements can be expanded by using AND, OR conditional statements operators and using xf:if, xf:else, xf:elseif.​
1. How can I show content to Administrators?
Code:
<xf:if is="$xf.visitor.is_admin">[/INDENT]
[INDENT=2]    Show content...[/INDENT]
[INDENT=2]</xf:if>
2. How can I show content to...

Read more about this resource...
 
How can I display the content only for those users who have an Gravatar?
Code:
<xf:if is="{$xf.visitor.gravatar}">
Show content...
</xf:if>

How can I display the content only for staff?
Code:
<xf:if is="{$xf.visitor.is_staff}">
Show content...
</xf:if>

How can I display the content only for users who have not confirmed email address?
Code:
<xf:if is="{$xf.visitor.isAwaitingEmailConfirmation()}">
Show content...
</xf:if>
 
Its not working.

I do not want to show ads on private nodes.

I have 1 private node which is accessible to members only.

I am going to show adsense advertise on forum, so if ads are displayed on pages which adsense cant browse then its not good.

So i want to add conditional statement for that code, so that they wont get displayed on particular nodes and its threads.

Thank You
 
Its not working.

I do not want to show ads on private nodes.

I have 1 private node which is accessible to members only.

I am going to show adsense advertise on forum, so if ads are displayed on pages which adsense cant browse then its not good.

So i want to add conditional statement for that code, so that they wont get displayed on particular nodes and its threads.

Thank You

Code:
<xf:if is="in_array({$forum.node_id}, [X,Y,Z])">
                  Show content..
</xf:if>

Sites might want to show a notice to a member without an avatar, and using dynamic avatar.

I'm investigating :)

@BegemotUral thanks update
 
How to show a banner only inside of only the first post of each page of a thread?

How to show a banner only under the first post of each page of a thread?
 
How to show a banner only inside of only the first post of each page of a thread?

How to show a banner only under the first post of each page of a thread?


How to show a banner only under the first post of each page of a thread?
Code:
        <xf:if is="{$post.position} % {$xf.options.messagesPerPage} == 1">
        Show content..
    </xf:if>

How to show a banner only inside of only the first post of each page of a thread?
Code:
         <xf:if is="{$post.position} % {$xf.options.messagesPerPage} == 0">
               Show content..
      </xf:if>
 
I did not see it in the guide, so...
How about a syntax for the post author is the thread author?

This is the XF1 version:
Code:
35. How can I show content if the post author is the thread author?

<xen:if is="{$post.user_id} == {$thread.user_id}">
This content will show if the post author is the thread author
</xen:if>


I tried doing it like this but did not see no change:
Code:
<xf:if is="$xf.post.user_id == $xf.thread.user_id">
This content will show if the post author is the thread author
</xf:if>
 
Last edited:
How about a syntax for the post author is the thread author?
I have not tried, but what about this one?
Code:
<xf:if is="$post.user_id == $xf.thread.user_id"> This content will show if the post author is the thread author </xf:if>
or
Code:
<xf:if is="$post.user_id == $thread.user_id"> This content will show if the post author is the thread author </xf:if>
 
The location field is specified
Code:
<xf:if is="{$xf.visitor.location}">
    Show content...
</xf:if>

The website field is specified
Code:
<xf:if is="{$xf.visitor.website}">
    Show content...
</xf:if>

The signature is indicated.
Code:
<xf:if is="{$xf.visitor.signature}">
    Show content...
</xf:if>


The user activated
Code:
<xf:if is="{$xf.visitor.user_state} == 'valid'">
    Show content...
</xf:if>
 
Awaiting email confirmation (after editing):
Code:
<xf:if is="{$xf.visitor.user_state} == 'email_confirm_edit'">
    Show content...
</xf:if>

Email is not valid
Code:
<xf:if is="{$xf.visitor.user_state} == 'email_bounce'">
    Show content...
</xf:if>
 
Back
Top Bottom