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

Seperating primary and secondary usergroups in templates possible?

Discussion in 'Styling and Customization Questions' started by Luxus, Dec 24, 2012.

  1. Luxus

    Luxus Well-Known Member

    You can add a usergroup conditional in templates with this
    Code:
    <xen:if is="{xen:helper ismemberof, $user, 4}">something</xen:if>
    4 is the usergroup id. But does xenforo's template syntax make a difference between primary and secondary usergroups? What I want is a conditional for primary usergroups only, completly ignoring secondary usergroups.
     
  2. Syndol

    Syndol Guest

    <xen:if is="{$visitor.user_group_id} == 4">something</xen:if>
     
    Jake Bunce likes this.
  3. Luxus

    Luxus Well-Known Member

    Thanks, but strange is, usergroup ID 4 is for admins here and with the conditional above all registered users get administrator rank images. My code I used is this:
    Code:
    <!-- Start User Ranks -->
    <xen:if hascontent="true">
    <ul class="userRank">
    <xen:contentcheck>
    <xen:if is="{$visitor.user_group_id} == 4">
    <li class="administrator"></li>
    </xen:if>
    <xen:if is="{xen:helper ismemberof, $user, 5}">
    <li class="superModerator"></li>
    </xen:if>
    <xen:if is="{xen:helper ismemberof, $user, 6}">
    <li class="moderator"></li>
    </xen:if>
    </xen:contentcheck>
    </ul>
    </xen:if>
    <!-- End User Ranks -->
    It's in the message_user_info template. I can't explain it, because registered users have the ID of 2 and not 4.
     
  4. Syndol

    Syndol Guest

    That's because in my example I used $visitor which is the person viewing the page. What you want is $user
    Not sure if you are going for multiple css classes but if not you may want to consider using elseif statements such as <xen:elseif is="{xen:helper ismemberof, $user, 5}" />
     
    Jake Bunce and Luxus like this.
  5. Luxus

    Luxus Well-Known Member

    $user does the trick, thanks :)
    I tried to use xen:elseif is but the server isn't responding when I use it. I am using TMS and and apparently it takes longer to build a template if it contains xen:elseifs. I tried to increase the execution time or how it's called, but to no effect. Well, at least it's working now, regardless of how.
     
  6. Syndol

    Syndol Guest

    There should be no change in execution time.
    Try the following (not tested):
    HTML:
    <xen:if hascontent="true">
        <ul class="userRank">
        <xen:contentcheck>
            <xen:if is="{$user.user_group_id} == 4">
                <li class="administrator"></li>
            <xen:elseif is="{xen:helper ismemberof, $user, 5}" />
                <li class="superModerator"></li>
            <xen:elseif is="{xen:helper ismemberof, $user, 6}" />
                <li class="moderator"></li>
            </xen:if>
        </xen:contentcheck>
        </ul>
    </xen:if>
     
    Luxus likes this.
  7. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Added missing "/" to xen:elseif's in previous post.
     
    Luxus and Syndol like this.
  8. Luxus

    Luxus Well-Known Member

    With the "/" added it's working now :) So xen:if is doesn't require a "/" but xen:else if does?
     
  9. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Correct. xen:if has a separate closing tag, xen:elseif does not so it is self-closing.
     
    Luxus likes this.

Share This Page