Conditional Statements for XenForo 2

Conditional Statements for XenForo 2

I've been looking & looking so I'm here....

what is the conditional if a user has added xfmg media items to their profile? what I have:
Code:
<xf:if is="$extras.xfmg_media_count">
 <td><a href="{{ link('media/users', $user) }}" class="menu-fauxLinkRow-linkRow u-concealed">{$user.xfmg_media_count|number}</a></td>
 <xf:else />
 <td>0</td>
 </xf:if>
 
Last edited:
I've been looking & looking so I'm here....

what is the conditional if a user has added xfmg media items to their profile? what I have:
Code:
<xf:if is="$extras.xfmg_media_count">
<td><a href="{{ link('media/users', $user) }}" class="menu-fauxLinkRow-linkRow u-concealed">{$user.xfmg_media_count|number}</a></td>
<xf:else />
<td>0</td>
</xf:if>


for those still wondering the answer to query if user added media and if so, then lists the number...
Code:
<xf:if is="$xf.visitor.xfmg_media_count">
    <td><a href="{{ link('media/users', $user) }}">{$user.xfmg_media_count|number}</a></td>
   
    </xf:if>

1599006778469.webp
 
Any conditionals for dates?
I would like to show content only on a certain date..

Code:
<xf:if is="$xf.time > 1599606000 AND $xf.time < 1599692400">
Your code here...
</xf:if>

I think something like this should work.
 
I'm searching a conditional statements to check the actual node_id.
Unfortanely i only have access to $xf so i need to compare a array
with 'node-' prefix. What i have tried is.

<xf:if is="in_array($xf.reply.containerKey, 'node-' . $xf.options.photoPollForums)">
 
so here is a question about 2.2. there is a weird situation in 2.2 with new thread types. in article and question threads... first post is repeated on every page. so the conditional...

48. 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>

results in ads in both the top post and the post below it. it would be interesting to see if this can be resolved somehow. :LOL:
 
Not sure if it's been posted in the 15 pages but this one is wrong:
Code:
<xf:if is="!$xf.visitor.user_id">
  Show only members
<xf:else />
Show only guests
</xf:if>

It should be
Code:
<xf:if is="!$xf.visitor.user_id">
  Show only guests
<xf:else />
Show only members
</xf:if>
 
This is actually the opposite of what I thought. Or this is a mistake?
6. How can I show different content to members and guests?

Code:
<xf:if is="!$xf.visitor.user_id">
Show only members
<xf:else />
Show only guests
</xf:if>
 
If the user is logged in, then $xf.visitor.user_id returns a numeric value other than zero, the user's id, which is equal to true.
If the user is not logged in, then $xf.visitor.user_id returns zero which is equal to false.

  • ! comparison operator means NOT. So, "NOT true" means "false" and vice versa.
  • Therefore, !$xf.visitor.user_id return 1 (true) if $xf.visitor.user_id is zero. Other way of saying this, if visitor is not a member, then $xf.visitor.user_id is equal to zero which means false, and !$xf.visitor.user_id returns true.
  • Now, if we use this definition: <xf:if is="!$xf.visitor.user_id"> can be read as <xf:if is="NOT member">.
  • Finally, this makes the following piece of code valid.

Code:
<xf:if is="!$xf.visitor.user_id">
    Show only guests
<xf:else />
    Show only members
</xf:if>
 
Last edited:
<xf:if is="in_array({$forum.node_id}, [X,Y,Z])">
Show content..
</xf:if>

Doesn't work in post_macros, any idea what I can do ?
 
This worked for me: $thread.node_id
I'm trying to add conditional statement in the author_info of post_article_macro but nothing is working.

Code:
<xf:if is="in_array({$forum.node_id}, [11,12])">
</xf:if>

Code:
<xf:if is="$xf.visitor.canStartConversationWith($post.User)">
</xf:if>

Both of these don't work. Please help me.
 
Last edited:
Top Bottom