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

Multiple conditions in xenforo template syntax

Discussion in 'XenForo Development Discussions' started by CyberAP, Mar 6, 2011.

  1. CyberAP

    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>
     
  2. Kier

    Kier XenForo Developer Staff Member

    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>
     
    Wulfspider, Steve F, EQnoble and 14 others like this.
  3. CyberAP

    CyberAP Well-Known Member

    Thanks, that helped a lot!
     
    eTiKeTâ„¢ and Kier like this.
  4. CaptainMorgan

    CaptainMorgan Active Member

    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>
     
  5. Valhalla

    Valhalla Well-Known Member

    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: Nov 21, 2014
  6. CaptainMorgan

    CaptainMorgan Active Member

    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.
     

Share This Page