Copied to clipboard

Flag this post as spam?

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


  • Lee 1130 posts 3088 karma points
    Oct 10, 2009 @ 15:09
    Lee
    0

    Is There A Check If Node Has Children Method?

    I need to check if a node has child nodes and then do something?  Is there something in the Umbraco.Library that checks this and returns a boolean?

    Thanks in advance :)

  • Nik Wahlberg 639 posts 1237 karma points MVP
    Oct 10, 2009 @ 15:36
    Nik Wahlberg
    1

    if you're in a loop you would do soemthing like....

                <!-- where @id is the id of the current node in the loop -->
                <xsl:variable name="children" select="umbraco.library:GetXmlNodeById(@id)/node"/>
                <xsl:if test="count($children) > 0">
                  <!-- perform your actions here -->
                </xsl:if>

    HTH,
    Nik

     

  • Lee 1130 posts 3088 karma points
    Oct 10, 2009 @ 16:24
    Lee
    0

    Appreciated thanks :)

  • Stephan Lonntorp 195 posts 212 karma points
    Oct 10, 2009 @ 17:49
    Stephan Lonntorp
    1

    Depending on the context of the xslt, you don't always have to call the library method, you could just count the childnodes directly, i.e count($currentPage/node), or if you're in a loop, you could just as easy call count(./node) to count the children of the current node in the loop. Sometimes, the slight overhead of calling GetXmlNodeById can be avoided.

  • Nik Wahlberg 639 posts 1237 karma points MVP
    Oct 13, 2009 @ 15:35
    Nik Wahlberg
    0

    Stephan, good point.

  • Fourfinger 24 posts 44 karma points
    Feb 24, 2012 @ 11:20
    Fourfinger
    0

    I try the count(./node) but it doesn't return any values. If I try count(./*) it does work. Any thoughts on this? Or is this related to versions? I'm working in 4.5 at the moment.

Please Sign in or register to post replies

Write your reply to:

Draft