Conditional Statements for XenForo 2

Conditional Statements for XenForo 2

Idhae

Member
XF2: Using conditional statements, how do I identify if a page is a Index page (or) What's New page (or) Search Results page ...etc ?
17. How can I show content only at home?

Code:
<xf:if is="$template == 'forum_list'">
Show content...
</xf:if>

187960


<xf:if is="$template == 'whats_new'">
187961
 

Blast

Active member
How do I show content if a user is a member of a certain usergroup? I want to extend the user's postbit with designs. But whenever I do

Code:
<xf:if is="{{$xf.visitor.isMemberOf(x)}}">

    Show content...

</xf:if>
It will only show content if the logged in user is the one specified in the code. I kinda want to give certain usergroups a CSS class so I can configure them per usergroup.
 

AGPR

Member
Is it possible to show content only if page URL equals to something? For example to show the login form only if its the login page (/login/)
I cannot use template = login because the login must be implemented IN the login template.

Unless I create a template modification with a callback which will check in PHP if the page is the login. But it sounds like a bad solution. Or?
 

Finexes

Active member
Is it possible to show content only if page URL equals to something? For example to show the login form only if its the login page (/login/)
I cannot use template = login because the login must be implemented IN the login template.

Unless I create a template modification with a callback which will check in PHP if the page is the login. But it sounds like a bad solution. Or?
You could try:
HTML:
<xf:if is="$xf.uri == '/login/'">
    Your content
</xf:if>
 

woody

Active member
I used the following in XF1.5 so Google Ad Manager could pull page codes into GAM for ad targeting. What updates do these need to work? Thank you!

googletag.pubads().setTargeting('VisitorID', '{$visitor.user_id}');
googletag.pubads().setTargeting('Template', '{$contentTemplate}');
googletag.pubads().setTargeting('ForumID', '{$forum.node_id}');
googletag.pubads().setTargeting('ParentID', '{$forum.parent_node_id}');
 

cdub

Well-known member
14. How can I hide content from more than one user group?

Code:
<xf:if is="{{!$xf.visitor.isMemberOf([x, y])}}">
Hide content...
</xf:if>


This isn't working for me for some reason.... x & y= the number next to the user group url in admin tool?
 

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
I've tried a handful of possible options, none successful at returning a value....ANYONE know what this variable is?
 

woody

Active member
This is called in the header as part of the ad serving code. Obviously, this variable only returns a value on specific pages/sections, but I've used it successfully for a couple years with XF1.5 to target direct ad campaigns in GAM to specific sections of the site. The other 3 variables return values, I simply need to know this 4th variable.
 
Last edited:
Top