Conditional Statements for XenForo 2

Conditional Statements for XenForo 2

To get some variables to work in all ad positions, they need to be referenced as global like {$__globals.forum.node_id} instead of forum.node_id
 
Hi,
How I can show content after post x on every page in a thread, except in forums y and z?
 
Last edited:
Looking for a conditional statement for thread view that combines two requirement.
Not to appear in particular forum <xf:if is="{$__globals.forum.node_id} != XXX">
Only appear if thread has more than Y number of posts.
 
Hi there, I have read all the comments and everything but still haven't figured out how to add a widget to a specific thread, say thread number 5662

Any help?

Thanks
 
Did anyone have luck with detecting the default dynamic avatars? This would be good to have!
Code:
<xf:if is="$xf.visitor.getAvatarType() == 'default'">content</xf:if>
Hi there, I have read all the comments and everything but still haven't figured out how to add a widget to a specific thread, say thread number 5662

Any help?

Thanks
1. Create the widget you want to show in that thread with no position set.
2. Put this in a html widget in the Thread view: Sidebar position.
Code:
<xf:if is="$context.thread.thread_id == 5662">
    <xf:widget key="widget_key" />
</xf:if>
3. Replace widget_key with the widget key you made in step 1.
4. Check advanced mode and save.
 
Is it possible to wrap a conditional statement around a complete/whole widget?

As far as I see it, if you put a conditional statement around the contents of the widget, it still shows the widget, even if there's no content to show.

I'm trying to hide certain widgets from certain usergroups if there's an easier way of doing it?!
 
Is it possible to wrap a conditional statement around a complete/whole widget?

As far as I see it, if you put a conditional statement around the contents of the widget, it still shows the widget, even if there's no content to show.

I'm trying to hide certain widgets from certain usergroups if there's an easier way of doing it?!
Put the widget in a html widget and wrap it with your conditional.
1520709736144.webp
 
It works partially but not as desired.
I use thhis code in the widget html.

Code:
<div class="deskContent">
<div class="block">
    <div class="block-container">
         <h2 class="widget-tabs block-tabHeader tabs hScroller" data-xf-init="tabs h-scroller" data-state="replace" role="tablist">
             <span class="hScroller-scroll">
                 <a href="{{ link('whats-new/posts/') }}?skip=1"
                        class="tabs-tab is-active"
                        role="Threads mit den meisten Likes"
                        aria-controls="tab_lastest_threads">Threads mit den meisten Antworten</a>
                 <a href="{{ link('whats-new/posts/') }}?skip=1"
                        class="tabs-tab"
                        id="most_liked_threads"
                        role="tab">Threads mit den meisten Likes</a>
                 <a href="{{ link('whats-new/profile-posts/') }}?skip=1"
                        class="tabs-tab"
                        id="most_liked_postst"
                        role="tab">Beiträge mit den meisten Likes</a>
                  <a href="{{ link('whats-new/profile-posts/') }}?skip=1"
                        class="tabs-tab"
                        id="Most_viewed_threads"
                        role="tab">Meist gelesene Threads</a>
             </span>
         </h2>
         <ul class="tabPanes widget--tab">
             <li class="is-active" role="tabpanel" id="Threads_with_more_replies">
                 <xf:widget key="Threads_with_more_replies" />
             </li>
             <li role="tabpanel" aria-labelledby="most_liked_threads">
                 <xf:widget key="most_liked_threads" />
             </li>
             <li role="tabpanel" aria-labelledby="most_liked_postst">
                 <xf:widget key="most_liked_posts" />
             </li>
             <li role="tabpanel" aria-labelledby="Most_viewed_threads">
                 <xf:widget key="Most_viewed_threads" />
             </li>
         </ul>
     </div>
</div>
    </div>
<xf:css>
.widget-tabs {
    overflow: hidden;
    .tabs-tab {font-size: 13px;}
}
.widget--tab .block-minorHeader {display:none;}
</xf:css>

And this code in extra.less

Code:
@media all and (min-width: 800px) {
    .deskContent {
            display:block;
            margin: 0 auto;
}  
    .phoneContent {
           display:none;
}
 
}

The content of the wigget disappears as desired. But the block header of the widget is still displayed on the phone.

1520761702896.webp

Does anyone have an idea or suggested solution?
 
Seriously? Put a widget inside a widget?

Surely that'll just show the widget again?

I'm trying to hide the widget from certain usergroups.
Yes, that works, you need to uncheck all the positions and put them to the html widget
 
@DL6 Please excuse my ignorance, but I'm really stuck here, and have been trying for what seems like hours.

----------------
1. I've made an html widget called "test1". I've turned OFF all the display positions.
The contents is:
<xf:if is="{{$xf.visitor.isMemberOf(13)}}">
This text should show to only usergroup13.</p>
</xf:if>
----------------

2. I've then made another html widget called "test2. I've turned ON the position I want it to appear in.
The contents is:
<xf:if is="$xf.visitor.isMemberOf(13)">
<xf:widget key="test1" />
</xf:if>
----------------

Obviously the test2 widget shows, but also test1 does as well.

I really can't work out where I'm going wrong.

I'm trying to configure it so that the test1 widget will only show to usergroup13.
 
@Graham Smith Although it works but with the same result as mine.

1520782279100.webp

1520782176721.webp

The explanation is simple. The content will be hidden but the HTML widget itself will still be displayed. But then only without content.

@DL6 the idea was really good, but it does not solve the problem of Garham Smith or mine.

That was actually one thing I had hoped for with the release of Xenforo 2. Just as the video upload directly into the forum without having to use the Media Gallery.
 
Top Bottom