Conditional Statements for XenForo 2

Conditional Statements for XenForo 2

woody

Active member
googletag.pubads().setTargeting('VisitorID', '{$xf.visitor.user_id}'); <-- updated
googletag.pubads().setTargeting('Template', '{$template}'); <-- updated
googletag.pubads().setTargeting('ForumID', '{$forum.node_id}'); <-- same as XF1
googletag.pubads().setTargeting('ParentID', '{$forum.parent_node_id}'); <-- HELP
@Brogan - hate to bug you, but do you know what the 2.x variable is for $forum.parent_node_id - thank you :)
 

limboclub

Active member
Hi @eTiKeT™ - Are these two sets of examples not exactly the same?

How do they show and hide?

43. How can I show content in more than one forum?
Code:
<xf:if is="in_array({$forum.node_id}, [X,Y,Z])">
Show content..
</xf:if>

44. How do I hide content in multiple forums?
Code:
<xf:if is="in_array($forum.node_id, [x,y,z])">
Hide content..
</xf:if>

I ask because this isn't working to hide the content from the list of forums:

<xf:if is="in_array({$forum.node_id}, [54,74,302,93,142,167,263,113,374,396,399,330,310,31,165,57,31,408])">

Nor this:
<xf:if is="in_array($forum.node_id, [54,74,302,93,142,167,263,113,374,396,399,330,310,31,165,57,31,408])">

Nor this:

<xf:if is="!in_array({$forum.node_id}, [54,74,302,93,142,167,263,113,374,396,399,330,310,31,165,57,31,408])">

Nor this:

<xf:if is="!in_array($forum.node_id, [54,74,302,93,142,167,263,113,374,396,399,330,310,31,165,57,31,408])">

I'm sure I am doing something wrong - just no idea what.
 
Last edited:

limboclub

Active member
Why does this still show to users who are logged in?

<xf:if is="{$post.position} % {$xf.options.messagesPerPage} == 0 AND !{$message.conversation_id} AND !{$visitor.user_id}">
 

limboclub

Active member
Hi @eTiKeT™ - Are these two sets of examples not exactly the same?

How do they show and hide?

43. How can I show content in more than one forum?
Code:
<xf:if is="in_array({$forum.node_id}, [X,Y,Z])">
Show content..
</xf:if>

44. How do I hide content in multiple forums?
Code:
<xf:if is="in_array($forum.node_id, [x,y,z])">
Hide content..
</xf:if>

I ask because this isn't working to hide the content from the list of forums:

<xf:if is="in_array({$forum.node_id}, [54,74,302,93,142,167,263,113,374,396,399,330,310,31,165,57,31,408])">

Nor this:
<xf:if is="in_array($forum.node_id, [54,74,302,93,142,167,263,113,374,396,399,330,310,31,165,57,31,408])">

Nor this:

<xf:if is="!in_array({$forum.node_id}, [54,74,302,93,142,167,263,113,374,396,399,330,310,31,165,57,31,408])">

Nor this:

<xf:if is="!in_array($forum.node_id, [54,74,302,93,142,167,263,113,374,396,399,330,310,31,165,57,31,408])">

I'm sure I am doing something wrong - just no idea what.
After much searching and slamming of fist into desk...

In the Advertising system, use:

{$__globals.forum.node_id}

 

Mr. Jinx

Well-known member
Small typo I guess, @eTiKeT™ :

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>
Should be:
Code:
<xf:if is="$xf.visitor.user_id">
  Show only members
<xf:else />
Show only guests
</xf:if>
 

dethfire

Well-known member
Stunning this isn't in the official resources. So vital. Does anyone have a good list of template variables? I'm used to 1.5

I was using this to show an ad in the first post of every page. Anyone got a XF2 conversion?

<xen:if is="{$post.position} % {$xenOptions.messagesPerPage} == 0 AND !{$message.conversation_id} AND !{$visitor.user_id}">
 

OperaManiac

Well-known member
Question. I want to show content to only guests. but even for guests, that content should not appear in one particular forum.
I am currently using this:

PHP:
<xf:if is="!$xf.visitor.user_id">   
<xf:if is="$__globals.forum.node_id != NODEID">
CONTENT
</xf:if></xf:if>
Is this accurate? Can I combine the two statements?
 

rdn

Well-known member
Hi, this isn't working:

44. How do I hide content in multiple forums?
<xf:if is="in_array($forum.node_id, [x,y,z])">
Hide content..
</xf:if>

My complete condition:
PHP:
<xf:if is="$xf.visitor.user_id AND in_array($forum.node_id, [1,2,3,4])">
 

OperaManiac

Well-known member
seems like a similar case like mine 2 posts above. the AND operator did not work for me so i had to use nested if. i guess i would check AND operator again. $__globals.forum.node_id worked for me.
 

rdn

Well-known member
This doesn't work:
Code:
<xf:if is="$post.position % $xf.options.messagesPerPage == 0">
Or
Code:
<xf:if is="{$post.position} % {$xf.options.messagesPerPage} == 0">
on message_macros template.
 

limboclub

Active member
Question. I want to show content to only guests. but even for guests, that content should not appear in one particular forum.
I am currently using this:

PHP:
<xf:if is="!$xf.visitor.user_id">  
<xf:if is="$__globals.forum.node_id != NODEID">
CONTENT
</xf:if></xf:if>
Is this accurate? Can I combine the two statements?
Yes you can nest.
 

Davey-UK

Active member
Trying to add the following statements into an ad template. How would i combine the two?
Code:
<xf:if is="in_array(!$forum.node_id, [13,76,50,89,94,19,65,67,68,71,72,66])">
<xf:if is="$post.position % $xf.options.messagesPerPage==2 AND count($__globals.posts)>3">
I have tried the following, but with no luck.
Code:
<xf:if is="$post.position % $xf.options.messagesPerPage==2 AND count($__globals.posts)>3 AND in_array(!$forum.node_id, [13,76,50,89,94,19,65,67,68,71,72,66])">
Also tried the following
Code:
AND in_array(!{$forum.node_id}, [13,76,50,89,94,19,65,67,68,71,72,66])"
The ad shows inside the post content after post two, but trying to hide it in the nodes listed.

Any helpers would be greatly appreciated.

#44 in the conditionals list seems to be the same as "show in". I need "hide in".
 
Last edited:
Top