Conditional Statements for XenForo 2

Conditional Statements for XenForo 2

Hello!

How can I display a widget inside a category, above the nodes?

I tried tweaking example 43 as follows:
Code:
<xf:if is="$forum.category_id == 5">
    <xf:widget key="iphoneiosnode" />
</xf:if>
and insert it both in category_view and forum_view without results. any tips?
 
Hello!

How can I display a widget inside a category, above the nodes?

I tried tweaking example 43 as follows:
Code:
<xf:if is="$forum.category_id == 5">
    <xf:widget key="iphoneiosnode" />
</xf:if>
and insert it both in category_view and forum_view without results. any tips?
I believe there's an addon that does this. Check on resources page.
 
I believe there's an addon that does this. Check on resources page.
I think I have seen that, it allows displaying a widget above a category in the forum_list, in my case, the forum is organised as follow:

Main Category
Sub Category1
Node
Node
Node
Sub Category2
Node
Node
Node

My goal is to display a widget once entered "sub Category1" and not above it in the forum_list


Maybe you're talking about another resource?
 
I think I have seen that, it allows displaying a widget above a category in the forum_list, in my case, the forum is organised as follow:

Main Category
Sub Category1
Node
Node
Node
Sub Category2
Node
Node
Node

My goal is to display a widget once entered "sub Category1" and not above it in the forum_list


Maybe you're talking about another resource?

I believe this might help you to achieve what you want

 
I believe this might help you to achieve what you want

no that's not it. it only allows the display of widget between node categories in the forum list. my goal is to display a widget INSIDE a category (as explained before)

thank you though!
 
Is there a conditional statement to see if a user has "Receive news and update emails" enabled or disabled?

Edit:
Nvm. I figured it out by playing around a bit.
HTML:
<xf:if is="{$xf.visitor.Option.receive_admin_email}">
       display content
</xf:if>
 
Last edited:
Any solution for this ?

PHP:
<xf:if is="{{$xf.visitor.isMemberOf([3, 4])}} OR $forum.node_id != 2">

Show Content for Group 3,4 in Forum 2

    <xf:else />

Show no Content  

</xf:if>

seems this works

PHP:
<xf:if is="$xf.visitor.isMemberOf([3,4]) || !in_array($__globals.forum.node_id, [2,3])">
    Show only members

    <xf:else />
Show no Content
</xf:if>
 
Last edited:
Display condition for widget.
In latest reviews widget, XFRM, what condition we use so that it will only display reviews from resource X?
Thanks
 
The display condition field isn't for that.

It affects where and how the widget is displayed, not the content.

It would require a custom coded widget for that.
 
Is there a condition to check if a specific member is online?
For example:

if (userid1 == online) then display something
 
Is there a condition to check if a specific member is online?
For example:

if (userid1 == online) then display something

Assuming that the $user variable is available in your template, you could use the following:

HTML:
<xf:if is="$user.isOnline()">
    User is online
</xf:if>
 
I have a conditional question that I could use a hand with:

Users on my forum want to be able to see when someone quotes their post by having the quote highlighted in a different colour. Is there a way to isolate just one's quotes and change the colour?

Thanks.
 
I have a conditional question that I could use a hand with:

Users on my forum want to be able to see when someone quotes their post by having the quote highlighted in a different colour. Is there a way to isolate just one's quotes and change the colour?

Thanks.
I haven't tested this, but I think something like this might work:

In: bb_code_tag_quote

Replace:
Code:
<blockquote class="bbCodeBlock bbCodeBlock--expandable bbCodeBlock--quote">

With:
Code:
<xf:if is="{$name} == {$xf.visitor.username}">
    <blockquote class="bbCodeBlockUser bbCodeBlock--expandable bbCodeBlock--quote">
<xf:else />
    <blockquote class="bbCodeBlock bbCodeBlock--expandable bbCodeBlock--quote">
</xf:if>

In extra.less, add:

Code:
.bbCodeBlockUser {
  margin: .75em 0;
  background: #4a007d;
  border: 1px solid #ed19ff;
    border-left-width: 1px;
    border-left-style: solid;
    border-left-color: rgb(237, 25, 255);
  border-left: 3px solid #e214ff;
}

Feel free to tweak the colors of course, I just did that quickly via inspect element to see how that'd come out.
 
Last edited:
I haven't tested this, but I think something like this might work:

In: bb_code_tag_quote

Replace:
Code:
<blockquote class="bbCodeBlock bbCodeBlock--expandable bbCodeBlock--quote">

With:
Code:
<xf:if is="{$name} == {$xf.visitor.username}">
    <blockquote class="bbCodeBlockUser bbCodeBlock--expandable bbCodeBlock--quote">
<xf:else />
    <blockquote class="bbCodeBlock bbCodeBlock--expandable bbCodeBlock--quote">
</xf:if>

In extra.less, add:

Code:
.bbCodeBlockUser {
  margin: .75em 0;
  background: #4a007d;
  border: 1px solid #ed19ff;
    border-left-width: 1px;
    border-left-style: solid;
    border-left-color: rgb(237, 25, 255);
  border-left: 3px solid #e214ff;
}

Feel free to tweak the colors of course, I just did that quickly via inspect element to see how that'd come out.
Hi,

this code does not appear in any template:

Code:
<blockquote class="bbCodeBlockUser bbCodeBlock--expandable bbCodeBlock--quote">
 
I'd suggest to compare user_id instead of the user name. I should be available via $attributes.member.

untested:

Find:
Code:
<blockquote data-attributes="{{ $attributes.member ? ('member: ' . $attributes.member) : '' }}" data-quote="{{ $name ?: null }}" data-source="{{ $source ? ($source.type . ': ' . $source.id) : '' }}"
    class="bbCodeBlock bbCodeBlock--expandable bbCodeBlock--quote js-expandWatch">

Replace:
Code:
<blockquote data-attributes="{{ $attributes.member ? ('member: ' . $attributes.member) : '' }}" data-quote="{{ $name ?: null }}" data-source="{{ $source ? ($source.type . ': ' . $source.id) : '' }}"
    class="bbCodeBlock bbCodeBlock--expandable bbCodeBlock--quote js-expandWatch {{ ($attributes.member == $xf.visitor.user_id) ? "bbCodeBlock--quote-self" : "" }}">

extra.less:
Code:
.bbCodeBlock--quote-self {
    .border-color: red;
    /* any other styles you might like */
}
 
Need the conditional statement for
1- Hiding forum_view content (topic list) from specific users of specific forum node.

For example how can I hide a forum node id 3 from the user groups 1,2 but it should show the content for 3,4 user groups and other forum nodes should not be affected.?
Please help.

Code:
<xf:if is="{{$xf.visitor.isMemberOf([3,4])}} && {{!$xf.visitor.isMemberOf([1,2])}} && in_array($__globals.forum.node_id, [3])">

This does hide the content but it hides for all other nodes as well. I have used this conditional statement in forum_view template.
 
This does hide the content but it hides for all other nodes as well. I have used this conditional statement in forum_view template.
in the template forum_view the variable $forum should be available.

So I assume you can replace this part:

in_array($__globals.forum.node_id, [3])

with:

in_array($forum.node_id, [3])

or, if you only have 1 forum just:

$forum.node_id == 3


But, depending on your requirements you might need something like this:

HTML:
<xf:if is="$forum.node_id == 3">
    <xf:if is="$xf.visitor.isMemberOf([3,4]) && !$xf.visitor.isMemberOf([1,2]) ">
        <!-- User can view node 3 -->
    <xf:else />
        <!-- user cannot view node 3 -->
    </xf:if>
<xf:else />
   <!-- node id is not 3 (any other node) -->
</xf:if>
 
Top Bottom