XF 2.1 Change the font colours by gender on members online widget

I am trying to change the font colour of each gender on the member's online widget. Male members will be a blue font, the female members will be a pink font.
I have tried to add an If conditional statement using the variable $user.gender. So if $user.gender == male then add style.
Unfortunately, it will not work? Below is the code I am using to find which members are female or male, then I will add a css class to each gender to change the font colour.
Code:
<xen:if is="{$user.gender} == 'male'">male<xen:elseif is="{$user.gender} == 'female'" />female<xen:else />none</xen:if>

Can anybody help? Thanks
 
Gender is now just a custom userfield in XF2 if you upgraded so you need a little more code. Looks like this works in the template: widget_members_online

Change: (around line 66)

Code:
                        <xf:foreach loop="$online.users" value="$user"><xf:trim>
                            <li><xf:username user="$user" rich="true" class="{{ !$user.visible ? 'username--invisible' : '' }}" /></li>
                        </xf:trim></xf:foreach>

To:

Code:
                        <xf:foreach loop="$online.users" value="$user"><xf:trim>
                            <li><xf:username user="$user" rich="true" class="{{ !$user.visible ? 'username--invisible' : '' }}{{ $user.Profile.custom_fields.gender == 'male' ? ' user--male' : '' }}{{ $user.Profile.custom_fields.gender == 'female' ? ' user--female' : '' }}" /></li>
                        </xf:trim></xf:foreach>
 
Gender is now just a custom userfield in XF2 if you upgraded so you need a little more code. Looks like this works in the template: widget_members_online

Change: (around line 66)

Code:
                        <xf:foreach loop="$online.users" value="$user"><xf:trim>
                            <li><xf:username user="$user" rich="true" class="{{ !$user.visible ? 'username--invisible' : '' }}" /></li>
                        </xf:trim></xf:foreach>

To:

Code:
                        <xf:foreach loop="$online.users" value="$user"><xf:trim>
                            <li><xf:username user="$user" rich="true" class="{{ !$user.visible ? 'username--invisible' : '' }}{{ $user.Profile.custom_fields.gender == 'male' ? ' user--male' : '' }}{{ $user.Profile.custom_fields.gender == 'female' ? ' user--female' : '' }}" /></li>
                        </xf:trim></xf:foreach>


Thank you so much for your help Russ, works great!!
 
Top Bottom