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

Is there a reason to use hascontent instead of just an is check?

Jaxel

Well-known member
#1
Code:
<xen:if hascontent="true">
    <ul class="adminList">
        <xen:contentcheck>
        <xen:foreach loop="$admins" value="$user">
            <li><xen:username user="$user" rich="true" /></li>
        </xen:foreach>
        </xen:contentcheck>
    </ul>
</xen:if>
VS
Code:
<xen:if is="{$admins}">
    <ul class="adminList">
        <xen:foreach loop="$admins" value="$user">
            <li><xen:username user="$user" rich="true" /></li>
        </xen:foreach>
    </ul>
</xen:if>
Why choose the content check instead of just doing the if is?
 

jmurrayhead

Well-known member
#3
I used this for replacing the moderatorBar with a generic userBar. It shows the bar if there is content to be shown, regardless if regular user or admin/moderator.
 

Jeremy

Well-known member
#5
Well, in the example you quoted, not using hascontent would duplicate conditionals that you have to manage. One to show if at least one is present, and then once again for each individual item. hascontent reduces that so you only have to manage each inner conditional once.