Copied to clipboard

Flag this post as spam?

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


  • Garrett Fisher 341 posts 496 karma points
    Feb 19, 2010 @ 21:58
    Garrett Fisher
    0

    check if parent page has certain property

    Hi,

    I have a property on my document type called "ShowLinkToSubpages", which I use to decide whether or not to show tertiary links in the sidebar of each page.  It just of course iterates through the child nodes of the CURRENT page and displays those links.  What I'd like to do ON THE THIRD-TIER (child) PAGES, though, is to ALSO display these links, that is, links to the SIBLINGS.  I'd like to check if the current page's Parent page has ShowLinkToSubpages set to true, then call a Macro whose XSLT will write the Sibling links.

    So I would like help with Two things: the XSLT to check the Parent node's property value, and the XSLT to list the Siblings of the current page.

    Thanks in advance,

    Garrett

  • Kenneth Solberg 227 posts 418 karma points
    Feb 19, 2010 @ 22:11
    Kenneth Solberg
    0

    You can do this quite entirely from XSLT if i understand you correct. I assume level 2 is 2nd tier:

    <xsl:for-each select=$currentPage/ancestor-or-self::node [@level = 2 and string(data [@alias = 'ShowLinkToSubpages']) = '1']/node">
    <a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName" /></a>
    </xsl:for-each>
  • Kenneth Solberg 227 posts 418 karma points
    Feb 19, 2010 @ 22:15
    Kenneth Solberg
    0

    Ops, some bad grammar there ... and the select missed a " in front.

  • Garrett Fisher 341 posts 496 karma points
    Feb 19, 2010 @ 23:04
    Garrett Fisher
    0

    Thanks for your reply--

    That code is giving me an error: Error reading XSLT file: \xslt\SidebarContent.xsl.  And I added the leading ".

    Anyways, I need to be able to access the parent of This page Specifically, not everything on a certain Level.  If I am ON a certian level, I need to display Children, and if I am another, different certain level, I ned to display Siblings.  Understand?

    Thanks again,

    Garrett

  • Kenneth Solberg 227 posts 418 karma points
    Feb 20, 2010 @ 08:34
    Kenneth Solberg
    0

    The Xpath will only match nodes with that property so it wont display children of other nodes. However, if you could do a <textarea><xsl:copy-of select="$currentPage" /></textarea> and copy the XML here it would be easier to help.

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Feb 20, 2010 @ 10:53
    Chriztian Steinmeier
    0

    Hi Garrett,

    Checking for a property on the parent page is done using the parent:: axis:

    <xsl:if test="$currentPage/parent::node[data[@alias = 'ShowLinkToSubpages'] = 1]">
        ...
    </xsl:if>

    - or using the shorthand "..":

    <xsl:if test="$currentPage/..[data[@alias = 'ShowLinkToSubpages'] = 1]">
        ...
    </xsl:if>

    Listing the siblings of $currentPage is done by taking the children of $currentPage's parent. Messing around with preceding-sibling:: and following-sibling:: isn't really feasible here; so:

    <xsl:for-each select="$currentPage/../node">
        ...
    </xsl:for-each>

    - or, if you're like me, using templates instead of for-each:

    <xsl:apply-templates select="$currentPage/../node" />

    /Chriztian

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Feb 20, 2010 @ 10:56
    Chriztian Steinmeier
    101

    - just realised you might actually need only the siblings, not including $currentPage:

    <xsl:apply-templates select="$currentPage/preceding-sibling::node | $currentPage/following-sibling::node" />

    /Chriztian

     

  • Garrett Fisher 341 posts 496 karma points
    Feb 22, 2010 @ 21:46
    Garrett Fisher
    0

    Rock n roll, Chriztian!  This code is exactly what I needed, works very well.  I appreciate your time :)

    //Garrett

Please Sign in or register to post replies

Write your reply to:

Draft