XF 2.1 Hide create thread button if reaction score is less than x

HJW

Active member
I'm trying to hide the new thread button if a users reaction is under 21. I thought this would work but it doesn't seem to and dumping the $user object just gets a null. Does someone know what I'm doing wrong?

Code:
<xf:pageaction if="$forum.canCreateThread() && $user.reaction_score|number > 20">
    <xf:button href="{{ link('forums/post-thread', $forum) }}" class="button--cta" icon="write">
        {{ phrase('post_thread') }}
    </xf:button>
</xf:pageaction>
 
If $user is null then it means it's not available in that template and you will need a different solution.

Why not use the user group promotion system?
 
@HJW the |number does number formatting which is not what you want for an integer comparison. Plus you want to check the guest (ir current user)

This should work;
HTML:
<xf:pageaction if="$forum.canCreateThread() && $xf.visitor.reaction_score > 20">
    <xf:button href="{{ link('forums/post-thread', $forum) }}" class="button--cta" icon="write">
        {{ phrase('post_thread') }}
    </xf:button>
</xf:pageaction>
 
I have to echo @Brogan's comments. Whereas the above solution would work, this is what user group promotions and node permissions are for.

You have to appreciate that the above HTML will hide the button, but it won't prevent someone from accessing the post-thread URL directly and still creating the thread.
 
Thanks, yes you're right the correct fix would be the user promotions but for the moment just want a quick fix to hide the button. I doubt many would go to the effort of finding the url
 
Top Bottom