Multiple conditions in xenforo template syntax

CyberAP

Well-known member
Is it possible to make such a condition as that?
PHP:
<xen:if is="@showTwitter" || "@showFacebook" || "@showYouTube">
Some content
<xen:else>
Other content
</xen:if>
 
You can do that like this:
HTML:
<xen:if is="@showTwitter || @showFacebook || @showYouTube">
	Some content
<xen:else />
	Other content
</xen:if>

However, you may also be interested in 'has content':
HTML:
<xen:if hascontent="true">
	<div class="sectionMain">
		<p>This will only show if there is something in
			the content check:</p>
		<xen:contentcheck>
			<xen:if is="@showTwitter">Twitter stuff</xen:if>
			<xen:if is="@showFacebook">Facebook stuff</xen:if>
			<xen:if is="@showYouTube">YouTube stuff</xen:if>
		</xen:contentcheck>
	</div>
<xen:else />
	<p>There was nothing to show.</p>
</xen:if>
 
The following always evaluates to true, though I cannot see why...

Code:
                    <xen:if hascontent="true">
                        <dt>{xen:helper userFieldTitle, musicStyle}:</dt>
                        <xen:contentcheck>                    
                            <dd>{xen:helper userFieldValue, $userFieldsInfo.musicStyle, $user, {$user.customFields.musicStyle}}</dd>
                        </xen:contentcheck>
                    <xen:else />
                        <dt>{xen:helper userFieldTitle, musicStyle}:</dt><dd>Unknown</dd>
                    </xen:if>
 
Most likely because of the <dd> tags. It will always evaluate to true because they are always present, unlike your custom user field, which may not have been set.

Code:
<xen:if hascontent="true">
     <dt>{xen:helper userFieldTitle, musicStyle}:</dt>
     <dd>
          <xen:contentcheck>
               {xen:helper userFieldValue, $userFieldsInfo.musicStyle, $user, {$user.customFields.musicStyle}}
          </xen:contentcheck>
     </dd>
<xen:else />
     <dt>{xen:helper userFieldTitle, musicStyle}:</dt>
     <dd>Unknown</dd>
</xen:if>
 
Last edited:
Most likely because of the <dd> tags. It will always evaluate to true because they are always present, unlike your custom user field, which may not have been set.

I've since removed them and it still evaluates to true... you should note too that there are no <dd> tags inside the xen:contentcheck area, which is where it looks to find anything.
 
But how to write

<xen:if is="@showTwitter == '1' " || "@showFacebook == '1'" || "@showYouTube == '1'">

?

=>

<xen:if is="{$fieldId}=='1' || {$fieldId}=='2'">
 
Last edited:
Top Bottom