Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Steve 472 posts 1216 karma points
    Jan 15, 2015 @ 22:17
    Steve
    0

    Check for Boolean Attribute on Node

    I am a little rusty on how you would check for wheather a node has an attribute and wheather it is "true".

    If the attribute is "true", then I would like to add ''target="_blank' to the <a> associated with it.

    Help?

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Jan 15, 2015 @ 22:27
    Dennis Aaen
    1

    Hi Steve,

    Here is the documentation on using the true/false property editor.

    http://our.umbraco.org/documentation/using-umbraco/backoffice-overview/property-editors/built-in-property-editors/True-False

    <xsl:if test="string(umbracoNaviHide) = '1'">
        <xsl:attribute name="target">
            _blank
        </xsl:attribute>
    </xsl:if>

    Where the umbracoNaviHide is the propertyAlias of the true / false field

    Hope this helps,

    /Dennis

  • Chriztian Steinmeier 2798 posts 8788 karma points MVP 7x admin c-trib
    Jan 15, 2015 @ 23:36
    Chriztian Steinmeier
    0

    Hi Steve/Dennis,

    Actually, there's no need to do the string conversion - this will work just fine:

    <xsl:if test="umbracoNaviHide = 1">
    

    - Looks much better too, if you ask me :-)

    Be sure to always test for equality, though - or use the not() function to test for inequality, e.g.:

    <xsl:if test="not(umbracoNaviHide = 1)">
    

    This takes care of edge cases where the property doesn't exist...

    /Chriztian

  • Steve 472 posts 1216 karma points
    Jan 16, 2015 @ 14:39
    Steve
    0

    I am sorry, I guess I wasn't clear. I don't rember how to properly access and change an attribute such as "target" on a href, if the test for a node property is equal to "true". Here is what I have so far:

    <xsl:if test="$node != ''">
       <a>
              <xsl:attribute name="href">
                <xsl:choose>
    
    
                  <xsl:when test="$node[name() = 'ExternalLink']">
                    <xsl:value-of select="$node/url" />
                  </xsl:when>
    
                  <xsl:otherwise>
                    <xsl:value-of select="umbraco.library:NiceUrl($node/@id)" />
                  </xsl:otherwise>
                </xsl:choose>
              </xsl:attribute>
    
              <xsl:attribute name="target">
               <xsl:if test="externalUrl = '1'">
               <xsl:value-of select="@target">
              </xsl:attribute>
              <span>
                <xsl:call-template name="node-name">
                  <xsl:with-param name="node" select="$node" />
                </xsl:call-template>
              </span>
            </a>
    
      </xsl:if>
Please Sign in or register to post replies

Write your reply to:

Draft