Conditional Statements for XenForo 2

Conditional Statements for XenForo 2

Does anyone know the conditional statement for showing/hiding the user banner in threads?

Edit: I mean a specific user banner.
 
Last edited:
I have a conditional working fine to hide content from a forum node <xf:if is="$forum.node_id != xx"> however this is not working hiding from a page node so I presume I need something other than $forum.node_id. I tried $page.node_id but no luck.

For example, to hide the sub navigation links on a page node:

Code:
<xf:if is="$page.node_id != 94">
                        <li>
                            <xf:macro name="nav_entry" arg-navId="{$navId}" arg-nav="{$navEntry}" arg-shortcut="alt+{$i}" />
                        </li>
                        </xf:if>

I'm sure this must be easy but is eluding me.

Can anyone please help?

Thank you.
 
I have a conditional working fine to hide content from a forum node <xf:if is="$forum.node_id != xx"> however this is not working hiding from a page node so I presume I need something other than $forum.node_id. I tried $page.node_id but no luck.

For example, to hide the sub navigation links on a page node:

Code:
<xf:if is="$page.node_id != 94">
                        <li>
                            <xf:macro name="nav_entry" arg-navId="{$navId}" arg-nav="{$navEntry}" arg-shortcut="alt+{$i}" />
                        </li>
                        </xf:if>

I'm sure this must be easy but is eluding me.

Can anyone please help?

Thank you.

Try $__globals.forum.node_id
 
I have a conditional working fine to hide content from a forum node <xf:if is="$forum.node_id != xx"> however this is not working hiding from a page node so I presume I need something other than $forum.node_id. I tried $page.node_id but no luck.

For example, to hide the sub navigation links on a page node:

Code:
<xf:if is="$page.node_id != 94">
                        <li>
                            <xf:macro name="nav_entry" arg-navId="{$navId}" arg-nav="{$navEntry}" arg-shortcut="alt+{$i}" />
                        </li>
                        </xf:if>

I'm sure this must be easy but is eluding me.

Can anyone please help?

Thank you.
You can see what variables are available for the template you are adding that code in by putting this into the template:
{{ dump(vars()) }}
 
Thanks, but how do I use that?
I take it that this that you tried <xf:if is="$page.node_id != 94"> is placed in a loop. If so, after the </xf:foreach> for that loop paste in {{ dump(vars()) }} and save. When you visit the Page, all the available variables for that template will be displayed.
 
I take it that this that you tried <xf:if is="$page.node_id != 94"> is placed in a loop. If so, after the </xf:foreach> for that loop paste in {{ dump(vars()) }} and save. When you visit the Page, all the available variables for that template will be displayed.
OK, so I have this:

Code:
<ul class="p-sectionLinks-list">
                    <xf:foreach loop="$selectedNavChildren" key="$navId" value="$navEntry" i="$i">
                        <xf:if is="$page.forum.node_id != 94">
                        <li>
                            <xf:macro name="nav_entry" arg-navId="{$navId}" arg-nav="{$navEntry}" arg-shortcut="alt+{$i}" />
                        </li>
                        </xf:if>
                    </xf:foreach>{{ dump(vars()) }}
                    </ul>

or Ozzy's suggestion

Code:
<ul class="p-sectionLinks-list">
                    <xf:foreach loop="$selectedNavChildren" key="$navId" value="$navEntry" i="$i">
                        <xf:if is="$__globals.forum.node_id != 94">
                        <li>
                            <xf:macro name="nav_entry" arg-navId="{$navId}" arg-nav="{$navEntry}" arg-shortcut="alt+{$i}" />
                        </li>
                        </xf:if>
                    </xf:foreach>{{ dump(vars()) }}
                    </ul>

And when I go to the page it just shows the page source above the page.
 
For some reason this works opposite it says on my site.
Code:
<xf:if is="!$xf.visitor.user_id">
  Show only members
<xf:else />
Show only guests
</xf:if>

The Show to guests shows to members and show to members shows to guests. Hmmm.. I just reversed what I wanted to do and it works fine.
 
For some reason this works opposite it says on my site.
Code:
<xf:if is="!$xf.visitor.user_id">
  Show only members
<xf:else />
Show only guests
</xf:if>

The Show to guests shows to members and show to members shows to guests. Hmmm.. I just reversed what I wanted to do and it works fine.
!$xf.visitor.user_id means if visitor does NOT have an ID.
Remove the ! and it should work as intended
 
How display custom user group banner on some nodes only ?
i solved this in message_macros
Code:
<xf:if is="in_array({$__globals.forum.node_id}, [33,34]) AND {$user.isMemberOf('22')}">
<div class="userBanner userBanner--lightGreen message-userBanner">name</div>
</xf:if>
 
Is there a way to show an ad banner in the middle of the first Thread? I don't want the advert to be below the first thread rather in between the first thread post at the middle of the content.

A conditional statement to achieve this will be appreciated. Thanks.
 
Number the posts from "0" on the page (thread starter) so post "5" would be "4". like this:

Code:
<xf:if is="$post.position % $xf.options.messagesPerPage == 0">
<div style="text-align:center;">

{your code}

</div>   
</xf:if>

For after 8th post:

<xf:if is="$post.position % $xf.options.messagesPerPage == 7">

For after 18th post:

<xf:if is="$post.position % $xf.options.messagesPerPage == 17">
 
Hi, Im not sure exactly how this works, but I think I post my request, and through the graciousness of others, I might get some help!

So, I'm looking for. statement that says: (on Watched forums page) If forum is watched show x (what's already there) if forum is not watched, show Y (a link to watch the unwatched forum)
 
Top Bottom