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

Template Syntax Questions

Discussion in 'XenForo Pre-Sales Questions' started by James, Aug 31, 2010.

  1. James

    James Well-Known Member

    I assume Kier/Mike have a reasoning for this:
    HTML:
    
    <xen:if hascontent="true">
        <div class="section staffOnline avatarList">
            <div class="secondaryContent">
                <h3>Staff Online Now</h3>
                <ul>
                    <xen:contentcheck>
                        <xen:foreach loop="$onlineUsers.records" value="$user">
                            <xen:if is="{$user.is_moderator} OR {$user.is_admin}">
                                <li>
                                    <xen:avatar user="$user" size="s" img="true" />
                                    <a href="{xen:link members, $user}" class="username">{$user.username}</a>
                                    <div class="muted">{xen:helper userTitle, $user}</div>
                                </li>
                            </xen:if>
                        </xen:foreach>
                    </xen:contentcheck>
                </ul>
            </div>
        </div>
    </xen:if>
    
    I'm just wondering why the 'is' is used here:
    HTML:
    <xen:if is="{$user.is_moderator} OR {$user.is_admin}">
     
  2. James

    James Well-Known Member

    Just a few template syntax-related queries:
    <xen:contentcheck> - what is the purpose of this? I understand it checks content but is it required every time you're running a content check?

    <xen:avatar user="$user" size="s" img="true" /> - does size allow small/medium/large?

    {xen:helper userTitle, $user} - wouldn't {xen:info} be more appropriate considering it grabs info from the user.

    <xen:foreach loop="$onlineUsers.records" value="$user"> - I assume loop is the actual variable it loops and value is the variable it is replaced with, such as foreach($onlineUsers['records'] AS $user)?

    <xen:if hascontent="true"> - What is this for? I'm assuming you wouldn't know if content exists until you've ran the code?

    <xen:if is="{$user.is_moderator} OR {$user.is_admin}"> - I am wondering why is_moderator and is_admin are keys in an array... wouldn't it be easier to see if they're part of a usergroup?

    Hopefully someone can clear up these questions for me!
     
  3. Enigma

    Enigma Well-Known Member

    What do you suggest as an alternative? "is" is shorter than "condition", and it sounds reasonable when read outloud: <xen:if is="true">do this</xen:if> -> if is true, do this.

    Just guessing here, but if there is no output produced inside <xen:contentcheck> then nothing inside the containing <xen:if hascontent="true"> block will be displayed.

    Sounds like a good assumption to me.

    Addressed above with what I assume is the correct answer.

    The array of user information contains flags indicating whether that user is a moderator and/or administrator. Sounds reasonable to me.
     
  4. James

    James Well-Known Member

    When you say it with that condition I mentioned it doesn't sound right. "If is user is moderator or user is admin".
    Perhaps... but when there's no staff online does the staff block still display? I think it does... *note to self: be more observant*
    Wouldn't it be more efficient to run a standard usergroup check than create another key just to define whether or not they're staff? Of course, I'm only assuming without knowing how this is ran.
     
  5. Enigma

    Enigma Well-Known Member

    I don't think it does.
     
  6. James

    James Well-Known Member

    I'll keep an eye out. Still wondering about what size parameters avatar accepts and whether xen:helper should be renamed to xen:info for more relevant terms!
     
  7. Mikey

    Mikey Well-Known Member

    Where did you get the code?
     
  8. Onimua

    Onimua Well-Known Member

    Mikey likes this.
  9. Mikey

    Mikey Well-Known Member

  10. Enigma

    Enigma Well-Known Member

    The xen:helper syntax is probably a generic system. You specify a "helper", which in this case is "userTitle". The helper is probably a method somewhere that in this case takes one parameter, the $user array, then determines and returns the user's user title. Perhaps the $user array contains a usergroup ID which is used to look up the title for that group, then it checks to see if there is a user title override for this user somewhere along the line, and returns the correct user title. Bonus—you can most likely extend the system to define your own helpers and use them in templates. ;).
     
  11. James

    James Well-Known Member

    Indeed but info is a more generic term as I think I'm safe to assume that:
    xen:helper userName, $user
    xen:helper postCount, $user
    return their corresponding parameter :)
     
  12. Mike

    Mike XenForo Developer Staff Member

    Enigma is basically correct with his reasoning.
     
    Enigma likes this.
  13. Shadab

    Shadab Well-Known Member

    I assume Kier/Mike named it helper because that term is common in MVC frameworks. A helper is usually a standalone function or static method which is used in the view layer to simplify certain repetitive tasks. Naming it a helper instead of info would help those who are already familiar with mvc frameworks.

    Take a look at the documentation on Helpers in some php mvc frameworks:
    Of course I could be wrong. :D
     
    James likes this.
  14. James

    James Well-Known Member

    Thanks Shadab. Mike I assume that <xen:avatar> takes s/m/l parameters?
     
  15. Mike

    Mike XenForo Developer Staff Member

    Yes.
     
  16. James

    James Well-Known Member

    Thanks for clarifying Mike.
    HTML:
    <xen:if is="{$user.is_moderator} OR {$user.is_admin}">
    Is there a specific reason why you decided to use is_moderator and is_admin keys to denote whether or not a user is part of a specific staff group? Wouldn't it have worked to run a standard usergroup check?
    Not too sure how the code works so I could be completely off, but still... I'm intrigued :)
     
  17. Mike

    Mike XenForo Developer Staff Member

    Moderator || Admin != User group :)
     
    James likes this.
  18. James

    James Well-Known Member

    Admins aren't usergroup-based? Awesome :)
     
  19. Kier

    Kier XenForo Developer Staff Member

    Nope, been there, done that. Doing it differently now.
     
    Been Told, David Thomas and James like this.
  20. James

    James Well-Known Member

    Different is good, keep up the innovative approach!
     

Share This Page