Copied to clipboard

Flag this post as spam?

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


  • umbracocool 108 posts 197 karma points
    Oct 25, 2012 @ 19:53
    umbracocool
    0

    Check if there a node by id

    Hello friends!, I want to do is to check whether a given node exists. I mean for example, if I pass the id, then check if that node exists. Thank you!

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Oct 25, 2012 @ 20:25
    Chriztian Steinmeier
    0

    Hi umbracocool,

    There's a couple of ways, depending on what you're doing, but this one should be good:

    <!-- Grab the node -->
    <xsl:variable name="node" select="umbraco.library:GetXmlNodeById(1200)" />
    
    <!-- Output a wrapper if it exists -->
    <xsl:if test="not($node[error])">
        <div class="starter">
            <xsl:value-of select="$node/@nodeName" />
        </div>
    </xsl:if>
    
    (This is because the XML you get back in case of an error is an <error> element with a message inside - otherwise you get the node's XML)

    /Chriztian

  • umbracocool 108 posts 197 karma points
    Oct 25, 2012 @ 20:31
    umbracocool
    0

    Thank you!, You're a genius brother God bless you!

Please Sign in or register to post replies

Write your reply to:

Draft