Highlight Content per Usergroup

Highlight Content per Usergroup 2023-04-19

No permission to download
Thanks @Ivancas
You've pointed something out, for a few posts now, that helps avoid these repeated errors.

This is what I understand now: my conditional statement is not wrong, it works fine and does what it is told. However, it triggers template errors in a special case, when an user concerned by one of the selected user group is deleted (or a guest but this parameter is not taken into account here).

This is also why your error message states:
Code:
[*]Generated by: Unknown account

To avoid this you have to add a add a second condition element in the conditional statement $post.User. This is confirmed by this message from @Xon, which is almost 5 years old! As you wrote previously the right code should be:
HTML:
{{ $post.User AND $post.User.isMemberOf('X') ? 'class-name' : '' }}

I will test this locally and I will publish a new version as soon as I have validated this fix.
 
Last edited:
This doesn't seem to work, the class is not applied with this syntax.
@Xon is there anything that would have changed since those years? Thanks.
 
You need to wrap the conditions in a pair of brackets like this:
Code:
{{ ($post.User AND $post.User.isMemberOf('X')) ? 'class-name' : '' }}
 
It was
HTML:
{{ $post.User AND $post.User.isMemberOf('X') ? 'class-name' : '' }}
Even like this (as you wrote) it doesn't work
Code:
{{ ($post.User AND $post.User.isMemberOf('X')) ? 'class-name' : '' }}


This how i used the template modification (post_macros):

Find:
HTML:
<div class="message-cell message-cell--user">

Replace:
HTML:
<div class="message-cell message-cell--user {{ $post.User.isMemberOf($xf.options.userGroup1) ? 'ucc-usergroup1Posts' : '' }}{{ $post.User.isMemberOf($xf.options.userGroup2) ? ' ucc-usergroup2Posts' : '' }}{{ $post.User.isMemberOf($xf.options.userGroup3) ? ' ucc-usergroup3Posts' : '' }}{{ $post.User.isMemberOf($xf.options.userGroup4) ? ' ucc-usergroup4Posts' : '' }}{{ ($post.USer AND $post.User.is_staff) ? ' ucc-staffPosts' : '' }}{{ $post.User.is_banned ? ' ucc-bannedPosts' : '' }}">

It works fine except that generates template errors when a deleted user is involved (i think) (regarding what you posted)

If the Replace code is:
HTML:
<div class="message-cell message-cell--user {{ $post.User AND $post.User.isMemberOf($xf.options.userGroup1) ? 'ucc-usergroup1Posts' : '' }}{{ $post.User AND $post.User.isMemberOf($xf.options.userGroup2) ? ' ucc-usergroup2Posts' : '' }}{{ $post.User AND $post.User.isMemberOf($xf.options.userGroup3) ? ' ucc-usergroup3Posts' : '' }}{{ $post.User AND $post.User.isMemberOf($xf.options.userGroup4) ? ' ucc-usergroup4Posts' : '' }}{{ ($post.User AND $post.User.is_staff) ? ' ucc-staffPosts' : '' }}{{ $post.User AND $post.User.is_banned ? ' ucc-bannedPosts' : '' }}">
It doesn't work at all.
 
The XF templates behaves very oddly with the ? : operator.

When you have;
{{ $post.User AND $post.User.isMemberOf('X') ? 'class-name' : '' }}
What XenForo renders it as is;
{{ $post.User AND ($post.User.isMemberOf('X') ? 'class-name' : '') }}
Which absolutely isn't what you want
 
You need to wrap the conditions in a pair of brackets like this:
Code:
{{ ($post.User AND $post.User.isMemberOf('X')) ? 'class-name' : '' }}
I must have made a typo because this code actually works perfectly. Thank you so much.

When you have;
{{ $post.User AND $post.User.isMemberOf('X') ? 'class-name' : '' }}
What XenForo renders it as is;
{{ $post.User AND ($post.User.isMemberOf('X') ? 'class-name' : '') }}
Which absolutely isn't what you want
I fully understand the difference, thank you for this explanation, really.
 
How much is right for you? Basically I didn't want to offer too many different user groups so that the discussion pages wouldn't turn into curious colored Christmas trees 🎄:D. Would 6 groups be a good compromise?
 
Thanks a lot Nicolas, a must have add-on really. Is there a chance to make this user-optional where user can choose if they want to highlight or not. I need this for my moderator group so they can highlight certain moderation-related posts when needed.

Thanks again!
 
Thanks,
However, the addThreadsOptionsColor still has the old syntax:
Code:
    <div class="structItem structItem--thread{{ $thread.prefix_id ? ' is-prefix' . $thread.prefix_id : '' }}{{ $thread.isIgnored() ? ' is-ignored' : '' }}{{ ($thread.isUnread() AND !$forceRead) ? ' is-unread' : '' }}{{ $thread.discussion_state == 'moderated' ? ' is-moderated' : '' }}{{ $thread.discussion_state == 'deleted' ? ' is-deleted' : '' }} js-inlineModContainer js-threadListItem-{$thread.thread_id} {{ $thread.User.isMemberOf($xf.options.userGroup1) ? 'ucc-usergroup1Threads' : '' }}{{ $thread.User.isMemberOf($xf.options.userGroup2) ? ' ucc-usergroup2Threads' : '' }}{{ $thread.User.isMemberOf($xf.options.userGroup3) ? ' ucc-usergroup3Threads' : '' }}{{ $thread.User.isMemberOf($xf.options.userGroup4) ? ' ucc-usergroup4Threads' : '' }}{{ $thread.User.is_staff ? ' ucc-staffThreads' : '' }}{{ $thread.User.is_banned ? ' ucc-bannedThreads' : '' }}" data-author="{{ $thread.User.username ?: $thread.username }}">
It is still needing
Code:
$thread.User AND
at the beginning of each conditional
 
  • Usergroup highlighting can now be enabled/disabled according to forums (nodes)
is this function available? I cant seem to find the option for it. ty.
 
I see what you mean but it's confusing. Instead of saying "Remove node conditional option causing error." You could say "Removed the function of highlighting usergroup content per node." Otherwise it sounds like a bug fix.
 
Top Bottom