Conditional Statements for XenForo 2

Conditional Statements for XenForo 2

Hello everyone,
Quick question, what rule should I use if I want to show content in the Resources section but only in specific categories (let's say 3 and 5)

To check multiple IDs, you can use in_array PHP function as shown below (xfrm_resource_view template is used for the sample) as it was also explained in 44. How do I hide content in multiple forums?:

Code:
<xf:if is="in_array($resource.resource_category_id, [3, 5])">
    show content
</xf:if>
 
I'm looking for a way to hide the Like button in posts that are from a specific member. So that this member cannot get any likes.
Is it possible with conditional statement?
 
I'm looking for a way to hide the Like button in posts that are from a specific member. So that this member cannot get any likes.
Is it possible with conditional statement?

Simple replacement template modification for post_macros.
Find:
Code:
<xf:react content="{$post}" link="posts/react" list="< .js-post | .js-reactionsList" />

Replace:
For a specific user_id = 2:
Code:
<xf:if is="$post.user_id !=2">
    <xf:react content="{$post}" link="posts/react" list="< .js-post | .js-reactionsList" />
</xf:if>

For multiple user_id [2,3,4]:
Code:
<xf:if is="!in_array($post.user_id, [2,3,4])">
    <xf:react content="{$post}" link="posts/react" list="< .js-post | .js-reactionsList" />
</xf:if>

I prefer to do that by setting a user group and setting it as additional user group for the users I'd like to apply this restriction instead dealing with multiple user IDs.

For user group ID = 20 (sample CannotBeLiked user group):
Code:
<xf:if is="!$post.User.isMemberOf(20)">
    <xf:react content="{$post}" link="posts/react" list="< .js-post | .js-reactionsList" />
</xf:if>

Of course this only hides the Like button. Controller action is still active and can be executed by using the correct route for the message. For example, your message's like action route: https://xenforo.com/community/posts/1409147/react?reaction_id=1
 
I use AMS by @Bob and try to get an conditional statement for widget. The created widget should only shown in one category.
I tried different ways but it doesn't work. What can i do?

$containerKey == "amsCategory-18"
 
I use AMS by @Bob and try to get an conditional statement for widget. The created widget should only shown in one category.
I tried different ways but it doesn't work. What can i do?

$containerKey == "amsCategory-18"

Widgets don't have the context of the host template, but $xf variable. Following should work:

$xf.reply.containerKey == "amsCategory-18"
 
@smozgur wow, this works great. Is it also possible to set an array or should i set $xf.reply.containerKey == "amsCategory-18" && "amsCategory-19"
 
What would be the template conditional to show content inside the first post of every thread in a specific node only? :unsure:
 
Why doesn't it show in the post thread page of this particular node (105)?

1587271300363.png

1587271346831.png

1587270751910.png

1587271043602.png

If I remove the xf tag, it will show.

1587270927767.png

1587271129278.png
 
Last edited:
I even tried this, still not working.

Code:
<xf:if is="in_array({$__globals.forum.node_id},[74])">   
               Show content.. haha

    </xf:if>
 
I'd like to run a script only on pages, posts, articles, media, and resources.

I currently have the script in the PAGE_CONTAINER above the end of the BODY.

What conditional should I put to run the script only on those content types?
 
What would be the template conditional to show content inside the first post of every thread in a specific node only? :unsure:

Of course you can directly edit the template but I would do it with template modification (post_macros) and simple replace following:

Code:
{{ bb_code($post.message, 'post', $post) }}

with the following:

Code:
<xf:if is="$post.isFirstPost() AND $thread.node_id==12">
    First post in specific node id : 12
</xf:if>
$0

It will show the additional text in the first post and just before the message this way.
 
Top Bottom