1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

XF 1.4 Conditionals on Member View

Discussion in 'Styling and Customization Questions' started by Amaury, Aug 19, 2015.

  1. Amaury

    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.PNG

    KHF Rank 2.PNG

    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.PNG

    KHF Rank 4.PNG

    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>
     
  2. Martok

    Martok Well-Known Member

    It's showing both because you are an administrator and a moderator. You need to use a xen:elseif (and determine which one you want to take precedence).

    Conditional Statements
     
    Amaury likes this.
  3. Amaury

    Amaury Well-Known Member

    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>
     
  4. Amaury

    Amaury Well-Known Member

    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>
     
  5. Martok

    Martok Well-Known Member

    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: Aug 19, 2015
    Amaury likes this.
  6. Amaury

    Amaury Well-Known Member

    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: Aug 19, 2015
  7. Martok

    Martok Well-Known Member

    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: Aug 19, 2015
    Nights and Amaury like this.
  8. Amaury

    Amaury Well-Known Member

    That's giving me a syntax error when I try it.
     
  9. Martok

    Martok Well-Known Member

    Details of the error?
     
  10. Amaury

    Amaury Well-Known Member

  11. Martok

    Martok Well-Known Member

    Apologies, I missed out the space and / in the xen:elseif statements :oops: I've corrected this now in my previous post.
     
    Amaury likes this.
  12. Amaury

    Amaury Well-Known Member

    Silly Martok!

    [​IMG]

    Rank 1.PNG Rank 2.PNG Rank 3.PNG Rank 4.PNG

    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.
     
    Martok likes this.

Share This Page