1
votes

I have a content element on my Umbraco site that I want to use as a container for content from another part of my document tree.

As shown in the image below, I need to reference all child pages under the /Content/Personal Site/Blog node from within the /Content/Frontpage Tabs/Featured Pages node.

Screen capture of site hierarchy

The XSLT I've borrowed for the job works fine if I drop it on a page below the "Personal Site" node, but yields nothing from below "Frontpage Tabs". I'm guessing because the currentPage is traversing that tree and not the Personal Site one.

The XSLT looks like this:

  <xsl:param name="currentPage"/>
  <xsl:variable name="numberOfPosts" select="3"/>
  <xsl:variable name="level" select="1"/>

  <xsl:variable name="pageNumber">
    <xsl:choose>
      <xsl:when test="umbraco.library:RequestQueryString('page') &lt;= 0 or string(umbraco.library:RequestQueryString('page')) = '' or string(umbraco.library:RequestQueryString('page')) = 'NaN'">1</xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="umbraco.library:RequestQueryString('page')"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <xsl:variable name="numberOfRecords" select="3" />

  <xsl:template match="/">

    <xsl:if test="$currentPage [name() = 'umbDateFolder']">
      <h2 class="page-title">
        Monthly Archives: <xsl:value-of select="umbraco.library:FormatDateTime(concat($currentPage/../@nodeName,'-',$currentPage/@nodeName,'-11T10:24:46'),'MMMM yyyy')"/>
      </h2>
    </xsl:if>

    <xsl:for-each select="$currentPage/ancestor-or-self::umbBlog//umbBlogPost">
        <xsl:sort select="./PostDate" order="descending" />

        <xsl:if test="position() &gt; $numberOfPosts * (number($pageNumber)-1) and
        position() &lt;= number($numberOfPosts * (number($pageNumber)-1) +
        $numberOfPosts )">

          <ul>
          <xsl:call-template name="showpost">
            <xsl:with-param name="post" select="."/>
          </xsl:call-template>
          </ul>

        </xsl:if>

     </xsl:for-each>

  </xsl:template>

  <xsl:template name="showpost">
    <xsl:param name="post"/>

    <li>
      <div class="excerpt">
        <a class="header" href="{umbraco.library:NiceUrl($post/@id)}" title="{$post/@nodeName}">
          <xsl:value-of select="$post/@nodeName" />
        </a>
        <xsl:value-of select="$post/bodyText" disable-output-escaping="yes" />
      </div>
      <a class="link-button" href="{umbraco.library:NiceUrl($post/@id)}">Read more</a>
    </li>

There'll be something obvious I need to change but I'm not well-versed enough in XSLT so any assistance is hugely appreciated.

2

2 Answers

2
votes

You should create a contentpicker type parameter in your macro (named "source", for example) and use the value of this parameter as the ID of the container node instead of currentPage. I often use that trick, and it works perfectly, and allow you to change the node in your admin backoffice.

1
votes

You should create a new variable which will be the node "Personal Site" and then get all the children. In order to create this node, you can add its ID with a key in the web.config.