XF 2.1 Widget Help

Cooking Ketogenic

Active member
Hello,

I want to show a widget only to guests. I can't figure what what to put as the "Display condition " I tried <xf:if is="!$xf.visitor.user_id"></xf:if> but the widget still shows if logged in.
 
What shoud I put into Display condition field if I want a widget to be desplayed on PC only and not on mobiles?
Thanks in advance.

No conditional for that, you'll just need to use CSS:

Code:
@media (max-width: @xf-responsiveWide)
{ 
    .p-body-sidebar [data-widget-definition="member_stat"] { display: none; }
}

Of course, you'll need to find the appropriate class.
 
No conditional for that, you'll just need to use CSS:

Code:
@media (max-width: @xf-responsiveWide)
{
    .p-body-sidebar [data-widget-definition="member_stat"] { display: none; }
}

Of course, you'll need to find the appropriate class.

thanks for your quick reply, but it looks chineese to me ). I'm talking about the New threads widget (Forum list: Sidebar).
do I have to modify tamplate? can't I just put an expression in a Display condition field pf a widget?
 
Display conditions are evaluated in code on the server so it isn't possible to evaluate at that point what size viewport a user has.

Russ' approach is correct but specifically for that widget you need the following:
Less:
@media (max-width: @xf-responsiveWide)
{
    .block[data-widget-key="new_threads_forum_list"] { display: none; }
}
This can be added to the extra.less template.

You may need to use a different value for data-widget-key. You can find the correct key to use when you're editing the widget:

194240
 
Display conditions are evaluated in code on the server so it isn't possible to evaluate at that point what size viewport a user has.

Russ' approach is correct but specifically for that widget you need the following:
Less:
@media (max-width: @xf-responsiveWide)
{
    .block[data-widget-key="new_threads_forum_list"] { display: none; }
}
This can be added to the extra.less template.

You may need to use a different value for data-widget-key. You can find the correct key to use when you're editing the widget:

View attachment 194240

it works! thank you!!!
 
Is hiding the sidebar widget with display:none the best approach? If the user is on mobile so the sidebar is sent down to the bottom of the page, there is not really much point in having it at all. What I think is needed is a display condition for the sidebar widgets which doesn't process them at all when not needed. I.e. doesn't run the database queries to get the data either. Otherwise you're pointlessly putting load on the database.
So if on mobile, don't process the sidebar at all.
I understand that we don't have the display size available to the server when building the page. But do we have information about the requesting device? Is there any way to do this currently?
 
So what display condition would be for not showing a widget in a forim with ID 18?

!$forum.node_id == 18 doesn't work (
I too cannot seem to get the forum.node_id condition to work for a widget to display in a forum_view sidebar. I tried global as well. Any ideas for how to write a conditional for a widget to display in a specific forum node id?
 
I too cannot seem to get the forum.node_id condition to work for a widget to display in a forum_view sidebar. I tried global as well. Any ideas for how to write a conditional for a widget to display in a specific forum node id?

try this

Code:
<xf:if is="$xf.reply.containerKey == 'node-123'">  
...
</xf:if>

replace 123 with your node id
 
Is hiding the sidebar widget with display:none the best approach? If the user is on mobile so the sidebar is sent down to the bottom of the page, there is not really much point in having it at all. What I think is needed is a display condition for the sidebar widgets which doesn't process them at all when not needed. I.e. doesn't run the database queries to get the data either. Otherwise you're pointlessly putting load on the database.
So if on mobile, don't process the sidebar at all.
I understand that we don't have the display size available to the server when building the page. But do we have information about the requesting device? Is there any way to do this currently?
I have the same question. I want to speed up page loading on mobile.
 
Top Bottom