I thought this would be simple enough but I'm having issues. New to XSLT.
For the site structure I have:
Main Site (portal site to display content from Sub Sites)
---- Sub Site 1 (has properties I'd like to access from News Article)
------- News Section
---------- News Article
---- Sub Site 2 (has properties I'd like to access from News Article)
------- News Section
---------- News Article
I'm trying to list all News Articles on the Main Site. Each News Article should then have an indicator of the Sub Site it's coming from. In this case I have a property for a CSS class on each Sub Site document type. I'll use that to style content coming from each Sub Site.
Here's my take on that - the thing you're missing is just that you need to get to the SiteArea node through the current node of the loop, not using $currentPage (which will always be the MainSite node where you're running the macro, right?).
I'm using a match template, but the result should be the same:
<xsl:param name="currentPage" />
<!-- Wherever you are, go to the "Main Site" node -->
<xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = 1]" />
<!-- Grab articles to show -->
<xsl:variable name="newsArticles" select="$siteRoot/SiteArea/umbNewsArea/umbNewsArticle[not(umbracoNaviHide = 1)]" />
<xsl:template match="/">
<xsl:apply-templates select="$newsArticles[position() <= $numberOfItems and position() > 1]" />
</xsl:template>
<!-- Template for an article -->
<xsl:template match="umbNewsArticle">
<!-- Grab this articles's SiteArea node -->
<xsl:variable name="mySection" select="ancestor::SiteArea" />
<li>
<h4><a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName"/></a></h4>
<p>
<xsl:choose>
<xsl:when test="$excerptLength > 0">
<xsl:value-of select="umbraco.library:TruncateString(umbraco.library:StripHtml(introduction), $excerptLength, '...')" disable-output-escaping="yes" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="introduction" disable-output-escaping="yes"/>
</xsl:otherwise>
</xsl:choose>
</p>
<small>
<xsl:value-of select="umbraco.library:ShortDate(@createDate)"/>
</small>
<span class="{$mySection/BackgroundColorCssClass}">
<xsl:value-of select="$mySection/@nodeName" />
</span>
</li>
</xsl:template>
Get 'grandparent' properties from child nodes
I thought this would be simple enough but I'm having issues. New to XSLT.
For the site structure I have:
Main Site (portal site to display content from Sub Sites)
---- Sub Site 1 (has properties I'd like to access from News Article)
------- News Section
---------- News Article
---- Sub Site 2 (has properties I'd like to access from News Article)
------- News Section
---------- News Article
I'm trying to list all News Articles on the Main Site. Each News Article should then have an indicator of the Sub Site it's coming from. In this case I have a property for a CSS class on each Sub Site document type. I'll use that to style content coming from each Sub Site.
Below is what I've tried so far:
This is giving me only Sub Site 1's properties. Is there something I'm missing to get News Articles to get their 'grandparent' property values?
Any help would be appreciated.
Thank you! Erik
Hi Erik,
Here's my take on that - the thing you're missing is just that you need to get to the SiteArea node through the current node of the loop, not using
$currentPage
(which will always be the MainSite node where you're running the macro, right?).I'm using a match template, but the result should be the same:
/Chriztian
Brilliant! Very much appreciated.
I definitely need to wrap my head around this a little more. I see the benefit with
xsl:template
. Just haven't gotten it yet.Thanks again, Erik
is working on a reply...