Similar Threads - User option for the widget

pipin

Member
After upgrading to 2.2.1 and activating the similar threads function we got mixed reactions from our users.

Would it be possible to add an user option to let the users decide if they want to have the similar threads widget under the threads?
 
Upvote 0
It could be done with a custom user field and a template edit with conditional statement.

This is from XF1 but the principle is the same:

 
@Brogan I am trying to build a custom field but I'm hitting a wall.

Created a custom user field ShowSimilarThreadsWidget and figure I need to edit the xfes_widget_similar_threads template:
Code:
<xf:if is="$threads is not empty">
    <div class="block" {{ widget_data($widget) }}>
        <div class="block-container">
            <xf:if is="$style == 'full'">
                <h3 class="block-header">{{ $title ?: phrase('xfes_similar_threads') }}</h3>


                <div class="block-body">
                    <div class="structItemContainer">
                        <xf:foreach loop="$threads" value="$thread">
                            <xf:macro name="thread_list_macros::item"
                                arg-allowInlineMod="{{ false }}"
                                arg-thread="{$thread}" />
                        </xf:foreach>
                    </div>
                </div>
            <xf:else />
                <h3 class="block-minorHeader">{{ $title ?: phrase('xfes_similar_threads') }}</h3>


                <ul class="block-body">
                    <xf:foreach loop="$threads" value="$thread">
                        <li class="block-row">
                            <xf:macro name="thread_list_macros::item_new_threads"
                                arg-thread="{$thread}" />
                        </li>
                    </xf:foreach>
                </ul>
            </xf:if>
        </div>
    </div>
</xf:if>

But where exactly do I put the xen:if is="!{$visitor.customFields.ShowSimilarThreadsWidget}"> and </xen:if>?
Can't get it to work
 
I'm not in my office so can't check the code but in general you need to wrap the entire block of code in the statement.
 
Thanks @Brogan for the quick reply. Tried that but it still didn't work. I think the "problem" is the xf:else in the template.
No rush but I hope you can help me figure it out.
 
Back in the office now.

I just noticed you're trying to use XF1 syntax and also the negative check.

You need to use this:
HTML:
<xf:if is="{$xf.visitor.Profile.custom_fields.ShowSimilarThreadsWidget}">
    <xf:if is="$threads is not empty">
        <div class="block" {{ widget_data($widget) }}>
            <div class="block-container">
                <xf:if is="$style == 'full'">
                    <h3 class="block-header">{{ $title ?: phrase('xfes_similar_threads') }}</h3>

                    <div class="block-body">
                        <div class="structItemContainer">
                            <xf:foreach loop="$threads" value="$thread">
                                <xf:macro name="thread_list_macros::item"
                                    arg-allowInlineMod="{{ false }}"
                                    arg-thread="{$thread}" />
                            </xf:foreach>
                        </div>
                    </div>
                <xf:else />
                    <h3 class="block-minorHeader">{{ $title ?: phrase('xfes_similar_threads') }}</h3>

                    <ul class="block-body">
                        <xf:foreach loop="$threads" value="$thread">
                            <li class="block-row">
                                <xf:macro name="thread_list_macros::item_new_threads"
                                    arg-thread="{$thread}" />
                            </li>
                        </xf:foreach>
                    </ul>
                </xf:if>
            </div>
        </div>
    </xf:if>
</xf:if>

I'll create a new guide for XF2 as the syntax is quite different.
 
Back
Top Bottom