Copied to clipboard

Flag this post as spam?

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


  • Vincent Ashby-Smith 67 posts 196 karma points
    Dec 22, 2009 @ 12:25
    Vincent Ashby-Smith
    0

    Get page name from node id

    Hi all wonder if someone can help, i'm getting the node id of a page, using the following piece of xslt:

    <xsl:value-of select="./data [@alias = 'quickLinksContent']" disable-output-escaping="yes"/>

    Is is possible to get the page name based on this, so for example say this node is 1024, currently i ouput this number but what i want to do is output the name of the page, so Homepage for example?

    Also i want to set up a link to this page based on this node id, i select the page using a content picker, how can i build the a link using this node id?

    Many Thanks

    Vince

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Dec 22, 2009 @ 12:41
    Dirk De Grave
    0

    vince,

    use

    <xls:value-of select="umbraco.library:NiceUrl(./data [@alias = 'quickLinksContent'])" />

    and surround this with an

    <xsl:if test="string(./data [@alias = 'quickLinksContent']) != ''>

    to check whether info is available from that property. If you don't, you'l get an error when saving the xslt as that property value is not available until runtime.

    Key is to use the NiceUrl() xslt extension method which takes the id of the node for which to build the link

    If you need the name of the page, use

    <xls:value-of select="umbraco.library:GetXmlNodeById(./data [@alias = 'quickLinksContent'])/@nodeName" />

    Hope this helps.

    Regards,

    /Dirk

     

  • Vincent Ashby-Smith 67 posts 196 karma points
    Dec 22, 2009 @ 12:50
    Vincent Ashby-Smith
    0

    Cheers Dirk thats brilliant, just the job! One final question is it possible to have some sort of recursive feature in xslt, i know in templates i've used recursive="true" so that umbraco will look at the parent for existing data, but how can you do this in xslt? Basically i have used the repeatable custom content to create a load of quick links at the bottom of a page and i want these to exist on every page not just the homepage!

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Dec 22, 2009 @ 13:10
    Dirk De Grave
    0

    Maybe this could help, or pass a recursive property to your xslt using this syntax:

    <umbraco:Macro InputParameter="[$otherTitle]" Alias="MyMacro" runat="server"></umbraco:Macro>

     

    Hope this helps.

    Regards,

    /Dirk

  • Vincent Ashby-Smith 67 posts 196 karma points
    Dec 22, 2009 @ 14:40
    Vincent Ashby-Smith
    0

    Hi unforutanely neither of those two solutions seems to work? I've attached my code, so maybe you could have a quick look? As you can see i've tried to apply the "ancestor-or-self::node" to the repeatble content variable, however the repeated content is only appearing on the hompage still, not any of the others. Maybe i'm missing something very obvious, but i can't see it yet!

     
      <!-- Input the repeatable custom contents property alias here -->
      <xsl:variable name="propertyAlias" select="string('quickLinks')"/>
     
      <xsl:template match="/">

        <!-- The fun starts here -->
        <xsl:if test="$currentPage/data [@alias = $propertyAlias]/items/item">

          <ul class="quickLink1">
            <xsl:for-each select="$currentPage/ancestor-or-self::node/data[@alias= $propertyAlias]/items/item">
                <li><a href="{umbraco.library:NiceUrl(./data [@alias = 'quickLinksContent1'])}"><xsl:value-of select="umbraco.library:GetXmlNodeById(./data [@alias = 'quickLinksContent1'])/@nodeName" /></a></li>
            </xsl:for-each>
          </ul>

          <ul class="quickLink2">
            <xsl:for-each select="$currentPage/ancestor-or-self::node/data[@alias= $propertyAlias]/items/item">
              <li><a href="{umbraco.library:NiceUrl(./data [@alias = 'quickLinksContent2'])}"><xsl:value-of select="umbraco.library:GetXmlNodeById(./data [@alias = 'quickLinksContent2'])/@nodeName" /></a></li>
            </xsl:for-each>
          </ul>

          <ul class="quickLink3">
            <xsl:for-each select="$currentPage/ancestor-or-self::node/data[@alias= $propertyAlias]/items/item">
              <li><a href="{umbraco.library:NiceUrl(./data [@alias = 'quickLinksContent3'])}"><xsl:value-of select="umbraco.library:GetXmlNodeById(./data [@alias = 'quickLinksContent3'])/@nodeName" /></a></li>
            </xsl:for-each>
          </ul>

          <ul class="quickLink4">
            <xsl:for-each select="$currentPage/ancestor-or-self::node/data[@alias= $propertyAlias]/items/item">
              <li><a href="{umbraco.library:NiceUrl(./data [@alias = 'quickLinksContent4'])}"><xsl:value-of select="umbraco.library:GetXmlNodeById(./data [@alias = 'quickLinksContent4'])/@nodeName" /></a></li>
            </xsl:for-each>
          </ul>

          <ul class="quickLink5">
            <xsl:for-each select="$currentPage/ancestor-or-self::node/data[@alias= $propertyAlias]/items/item">
              <li><a href="{umbraco.library:NiceUrl(./data [@alias = 'quickLinksContent5'])}"><xsl:value-of select="umbraco.library:GetXmlNodeById(./data [@alias = 'quickLinksContent5'])/@nodeName" /></a></li>
            </xsl:for-each>
          </ul>

          <ul class="quickLink6">
            <xsl:for-each select="$currentPage/ancestor-or-self::node/data[@alias= $propertyAlias]/items/items">
              <li><a href="{umbraco.library:NiceUrl(./data [@alias = 'quickLinksContent5'])}"><xsl:value-of select="umbraco.library:GetXmlNodeById(./data [@alias = 'quickLinksContent6'])/@nodeName" /></a></li>
            </xsl:for-each>
          </ul>

          <!-- Live Editing support for related links. -->
        <xsl:value-of select="umbraco.library:Item($currentPage/@id,$propertyAlias,'')" />
       </xsl:if>

  • Vincent Ashby-Smith 67 posts 196 karma points
    Dec 22, 2009 @ 15:29
    Vincent Ashby-Smith
    0

    Solved it, i really did miss something very obvious!!

Please Sign in or register to post replies

Write your reply to:

Draft