Copied to clipboard

Flag this post as spam?

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


  • Soeren Sprogoe 575 posts 259 karma points
    Aug 14, 2009 @ 13:28
    Soeren Sprogoe
    0

    Finding the ID of the homepage/top node

    Hi there,

    I've started to develop a lot of solutions, where one backend instance is used to administrate several sites. And there's one problem I always seem to run into, and haven't figured out the best way of solving yet:

    Imagine that you fx. want a "Latest News" box on each page on each site. They way to do this is to take the Top Node/Homepage, do a descendant-or-self::node to find all nodes of type "News", order it by date and show the top 3.

    But how do I figure out what the Top Node/Homepage is of the current site? What's the best way to do this?

    Hopes it makes sense :-)

    Best regards,
    Soeren S.

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Aug 14, 2009 @ 13:32
    Dirk De Grave
    0

    Soeren,

    How about this code snippet:

     

    <xsl:for-each select="$currentPage/ancestor-or-self::node [@level = 1]//node [@nodeTypeAlias = 'News' and position() &lt;= $numberOfItems]>
    <xsl:sort select="@createDate" order="descending" />
    bla..
    </xsl:for-each>

     

    Does that help?

     

    Cheers,

    /Dirk

  • Søren Linaa 255 posts 208 karma points
    Aug 14, 2009 @ 13:35
    Søren Linaa
    101

    Hi Søren

    I use this variable to get the ID of the top node of a tree

    <xsl:variable name="isFrontpage">
     <xsl:choose>
      <xsl:when test="count($currentPage/ancestor-or-self::node [@level=1]) != 0">
        <xsl:value-of select="$currentPage/ancestor-or-self::node [@level=1]/@id"/>
        </xsl:when>
      <xsl:otherwise>0</xsl:otherwise>
     </xsl:choose>
    </xsl:variable>
  • Soeren Sprogoe 575 posts 259 karma points
    Aug 14, 2009 @ 13:41
    Soeren Sprogoe
    0

    Brilliant!

    I chose to go with a variation of Linaa's example:

    <xsl:variable name="hpID" select="$currentPage/ancestor-or-self::node [@level=1]/@id"/>

    Thanks guys, been needing this simple stuff for some time now :-)

    /SoerenS

Please Sign in or register to post replies

Write your reply to:

Draft