• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

XF 1.1 What is wrong with this template condition?

RoldanLT

Well-known member
#1
Code:
<xen:if is="{$postId} == 2 AND !{$visitor.user_id} AND !in_array({$forum.node_id}, array(23,26,74,76,77,79,89,93,94,95,106,108,159,160,161,162,198))">
 
CONTENT HERE
 
</xen:if>
 
 
<xen:if is="{$postId} == 3 AND !{$visitor.user_id} AND !in_array({$forum.node_id}, array(23,26,74,76,77,79,89,93,94,95,106,159,160,161,162))">
 
CONTENT HERE
 
</xen:if>


It doesn't work or display.
 

Chris D

XenForo developer
Staff member
#2
Firstly, what template are you using this in?

Next, be methodical with it...

Break it down and test it piece by piece...

So first try:

Code:
<xen:if is="{$postId} == 2">
CONTENT
</xen:if>
If that works... try the next bit...

Code:
<xen:if is="{$postId} == 2 AND !{$visitor.user_id}">
CONTENT
</xen:if>
And keep going until you identify where it has gone wrong. Most of those conditions look correct so hopefully doing it like I've suggested above will single out the one that's wrong.
 

RoldanLT

Well-known member
#4
Firstly, what template are you using this in?

Next, be methodical with it...

Break it down and test it piece by piece...

So first try:

Code:
<xen:if is="{$postId} == 2">
CONTENT
</xen:if>
If that works... try the next bit...

Code:
<xen:if is="{$postId} == 2 AND !{$visitor.user_id}">
CONTENT
</xen:if>
And keep going until you identify where it has gone wrong. Most of those conditions look correct so hopefully doing it like I've suggested above will single out the one that's wrong.
I tested this code:

<xen:if is="{$postId} == 2">
TEST CONTENT
</xen:if>

It didn' t work :(
 

Chris D

XenForo developer
Staff member
#5
For that template, it wouldn't work.

ad_templates are for advert code - they don't have any parameters available to them.

So basically the ad_message_below template hasn't got a clue what $postId means.
 

RoldanLT

Well-known member
#9
Yeah that should work.
Still didn't work, I inserted it inside "message" template:

Code:
<article>
                <blockquote class="messageText ugc baseHtml{xen:if $message.isIgnored, ' ignored'}">
                    <xen:include template="ad_message_body" />
 
<xen:if is="{$postId} == 2">
TEST CONTENT
</xen:if>
 
                    {xen:raw $message.messageHtml}
                </blockquote>
            </article>
 

Chris D

XenForo developer
Staff member
#14
Are you trying to show content in the post with an ID of 2 (that is, out of all of the many posts on your forum, the single post with an ID of 2) or are you trying to show content in the post in every single thread that is the 2nd post in that thread?

If the latter, I think you want this:

<xen:if is="{$message.position} == 2">
TEST CONTENT
</xen:if>

But, actually, the position starts at 0 so the second post would be 1
 

RoldanLT

Well-known member
#15
Are you trying to show content in the post with an ID of 2 (that is, out of all of the many posts on your forum, the single post with an ID of 2) or are you trying to show content in the post in every single thread that is the 2nd post in that thread?

If the latter, I think you want this:

<xen:if is="{$message.position} == 2">
TEST CONTENT
</xen:if>

But, actually, the position starts at 0 so the second post would be 1
Still not working.