XF 1.4 Conditionals on Member View

Amaury

Well-known member
I've added a rank here, but for some reason, it's displaying both Administrator and Moderator for administrators:

KHF Rank 1.webp

KHF Rank 2.webp

In addition, for regular users, I want it to display the user titles from the user title ladder; for banned users, I want it to display Banned. What are the conditionals to use here?

KHF Rank 3.webp

KHF Rank 4.webp

This is my code so far in the member_view template:

Code:
                <dl><dt>{xen:phrase khflare_rank}:</dt>
                               <dd><xen:if is="{$user.is_admin}">{xen:phrase administrator}</xen:if>
                               <xen:if is="{$user.is_moderator}">{xen:phrase moderator}</xen:if></dd></dl>
 
Thanks, Martok. I was too tired to reply when I saw this (in fact, I had just awoken from unintentionally falling asleep from playing my PSP to shut things down), but I did try that yesterday a few times, and it gave me a syntax error:

Code:
<dl><dt>{xen:phrase khflare_rank}:</dt>
                               <dd><xen:if is="{$user.is_admin}">{xen:phrase administrator}<xen:else />
                               <xen:if is="{$user.is_moderator}">{xen:phrase moderator}</xen:if></dd></dl>
 
Okay, I got it by revising the code to:

Code:
<dl><dt>{xen:phrase khflare_rank}:</dt>
                               <dd><xen:if is="{$user.is_admin}">{xen:phrase administrator}<xen:else />
                               {xen:phrase moderator}</xen:if></dd></dl>

Strange. I just copied and pasted the code from the modification @Nights made on KH-Flare 2014's sidebar_online_users template, minus the Staff Member one, to make it so staff's assigned user group user titles always display under Staff Online Now, which is working, and adjusted it accordingly:

Code:
<div class="userTitle">
                                           <xen:if is="{$user.is_admin}">
                                                 {xen:phrase administrator}
                                           <xen:else />
                                            <xen:if is="{$user.is_moderator}">
                                                   {xen:phrase moderator}
                                             <xen:else />
                                                   {xen:phrase staff_member}
                                             </xen:if>
                                           </xen:if>
                                    </div>

Although I see that for the same change on KH-Flare 2015, he did it a bit differently:

Code:
<xen:foreach loop="$onlineUsers.records" value="$user">
                        <xen:if is="{$user.is_admin}">
                            <li>
                                <xen:avatar user="$user" size="s" img="true" />
                                <xen:username user="$user" rich="true" />
                                <xen:comment><div class="userTitle">{xen:helper userTitle, $user}</div></xen:comment>
                                    <div class="userTitle">
                                             {xen:phrase administrator}
                                    </div>
                            </li>
                        </xen:if>
                    </xen:foreach>
                    <xen:foreach loop="$onlineUsers.records" value="$user">
                        <xen:if is="!{$user.is_admin} && {$user.is_moderator}">                       
                            <li>
                                <xen:avatar user="$user" size="s" img="true" />
                                <xen:username user="$user" rich="true" />
                                <xen:comment><div class="userTitle">{xen:helper userTitle, $user}</div></xen:comment>
                                    <div class="userTitle">
                                               {xen:phrase moderator}
                                    </div>
                            </li>
                        </xen:if>
                    </xen:foreach>
 
Code:
<div class="userTitle">
<xen:if is="{$user.is_admin}">
{xen:phrase administrator}
<xen:else />
<xen:if is="{$user.is_moderator}" />
{xen:phrase moderator}
<xen:else />
{xen:phrase staff_member}
</xen:if>
</xen:if>
</div>

It's neater to use xen:elseif rather than a xen:else and then a xen:if:

Code:
<div class="userTitle">
<xen:if is="{$user.is_admin}">
{xen:phrase administrator}
<xen:elseif is="{$user.is_moderator}" />
{xen:phrase moderator}
<xen:else />
{xen:phrase staff_member}
</xen:if>
</div>

There's also one less closing /xen:if tag at the end.

Although this works for administrators and moderators, won't this show all other members as having a rank of staff member? Or do you have other code to prevent this?
 
Last edited:
I'm not done yet. :p That was going to be my next question now that I've got this sorted out.

Would this be correct for the remaining Registered user title ladder and Banned user group?

Code:
                <dl><dt>{xen:phrase khflare_rank}:</dt>
                               <dd><xen:if is="{$user.is_admin}">{xen:phrase administrator}<xen:else />{xen:phrase moderator}<xen:else />
                               {xen:helper userTitle, $user}<xen:else />{xen:phrase banned}</xen:if></dd></dl>
 
Last edited:
I'd have thought that this would be the conditional:

Code:
<dl>
<dt>
{xen:phrase khflare_rank}:
</dt>
<dd>
<xen:if is="{$user.is_admin}">
{xen:phrase administrator}
<xen:elseif is="{$user.is_moderator}" />
{xen:phrase moderator}
<xen:elseif is="{$user.is_banned}" />
{xen:phrase banned}
<xen:else />
{xen:helper userTitle, $user}
</xen:if>
</dd>
</dl>
 
Last edited:
Silly Martok!

you_are_awesome1.jpg


Rank 1.webp Rank 2.webp Rank 3.webp Rank 4.webp

I just need to remove a custom user title from one user because it's displaying that instead of the user title from where they are on the ladder. Registered can't use custom user titles, but I forgot to remove it when I demoted him due to inactivity. Oops.
 
Top Bottom