Template Syntax Questions

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}">
 
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!
 
I'm just wondering why the 'is' is used here:
HTML:
<xen:if is="{$user.is_moderator} OR {$user.is_admin}">
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.

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

<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)?
Sounds like a good assumption to me.

<xen:if hascontent="true"> - What is this for? I'm assuming you wouldn't know if content exists until you've ran the code?
Addressed above with what I assume is the correct answer.

<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?
The array of user information contains flags indicating whether that user is a moderator and/or administrator. Sounds reasonable to me.
 
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.
When you say it with that condition I mentioned it doesn't sound right. "If is user is moderator or user is admin".
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.
Perhaps... but when there's no staff online does the staff block still display? I think it does... *note to self: be more observant*
The array of user information contains flags indicating whether that user is a moderator and/or administrator. Sounds reasonable to me.
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.
 
... whether xen:helper should be renamed to xen:info for more relevant terms!
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. ;).
 
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. ;).
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 :)
 
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 :)
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
 
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 :)
 
Top Bottom