XF 2.1 How to show a thread view sidebar widget in a specific forum?

DeltaHF

Well-known member
I want a sidebar widget to be visible when viewing threads in a particular forum.

Using the Display Condition field, I would expect this to show the widget in threads with a node_id of 358:

Code:
$context.thread.node_id == 358

...but that does not work and the widget never displays.

Using an HTML template and dumping the variable confirms that it is, in fact, what I expect it to be. Using this configuration, for example, the widget shows "358" when viewing a thread in the target forum:

199160

But, when we add the Display Condition, the widget disappears from that same thread:

199161

What am I doing wrong?
 
It took a while, but I have figured this out on my own.

Although $context is available to use in the "Template" field, it is not actually defined when the "Display condition" is processed. This is extremely confusing; the actual variables available in the "Display condition" field need to be documented by XenForo.

Anyways, this is the condition you can use to display widgets per forum, where "123" is the forum ID:

Code:
$xf.reply.containerKey == 'node-123'
 
Again, untested, but try this:

Code:
in_array($xf.reply.containerKey, ['node-1', 'node-2', 'node-3']) AND $xf.visitor.isMemberOf(X)

Where X is the target usergroup ID.

That should only show to specific user groups in specific node ids.
 
Assuming that works, you could try this:

Code:
in_array($xf.reply.containerKey, ['node-1', 'node-2', 'node-3']) AND $xf.visitor.isMemberOf([x, y])

Where x and y are the multiple user groups.

You may find this guide useful:

 
Anyone an idea how to do this for all threads within a complete category (including dozends of forums), instead of adding each and every forums node-ID? Reason is, in this category users can create forums by themselves and the array can´t be static, since you´ld have to edit it every day.
 
Anyone an idea how to do this for all threads within a complete category (including dozends of forums), instead of adding each and every forums node-ID? Reason is, in this category users can create forums by themselves and the array can´t be static, since you´ld have to edit it every day.
I would try to negate the whole thing. Instead of adding every node ID you want it to be displayed, negate it and add all IDs which you don't want it to be displayed. That should stay more or less static.
Let's say you have node ids from 1 to 10 and you want them displayed in 4-10 (which then will grow).

Instead of doing
if node id 4, 5, 6, 7, 8, 9, 10
try
if NOT node id 1, 2, 3
 
Of course that would be plan C, but I don´t want to believe that it isn´t possible to target a category with the nested forums and threads.. Is XF really lacking of this?
 
I could be wrong, but I don't think the parent node-ids are included in the $xf variable.

You'd probably have to write a custom function in a plugin to achieve this.
 
I have not tested this, but I presume it will work:

Code:
in_array($xf.reply.containerKey, ['node-1', 'node-2', 'node-3'])

Just put all the nodes you want to include in that array.
Is there anything like this for subdomains as well? So if I want to hide a widget in a subdomain but show it in an another?
 
Back
Top Bottom