XF 2.2 Adding a conditional styling class to template

Mr Lucky

Well-known member
I want to have a message background which is different only for one user. I have added the class mod-message to post_macros by inserting the conditional lafter the existing two classes (message-body and js-selectToQuote)

Code:
<article class="message-body js-selectToQuote <xf:if is="$post.user_id == 9092">mod-message</xf:if>">

This does work but I am concerned it is not the correct way to do it as the inserted text showed red in the template edit.

Can anyone please confirm this is OK or a better way to achieve this? Thanks
 
Last edited:
Solution
I would try something like that, ternary syntax:
HTML:
<article class="message-body js-selectToQuote {{ ($post.user_id == 9092) ? ' mod-message' : '' }}">
I would try something like that, ternary syntax:
HTML:
<article class="message-body js-selectToQuote {{ ($post.user_id == 9092) ? ' mod-message' : '' }}">
 
Solution
Back
Top Bottom