简体   繁体   English

如何从单独的Umbraco节点获取子文档?

[英]How do I get the child documents from a separate Umbraco node?

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. 我在Umbraco网站上有一个内容元素,我想将其用作文档树另一部分内容的容器。

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. 如下图所示,我需要在/ Content / Frontpage选项卡/精选页面节点中引用/ Content / Personal Site / Blog节点下的所有子页面。

网站层次结构的屏幕截图

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". 如果我把它放在“个人网站”节点下面的页面上,我借用的XSLT工作正常,但是在“Frontpage Tabs”下面没有产生任何结果。 I'm guessing because the currentPage is traversing that tree and not the Personal Site one. 我猜是因为currentPage遍历那棵树而不是个人站点。

The XSLT looks like this: XSLT看起来像这样:

  <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. 我需要改变一些明显的东西但是我对XSLT不够精通,所以非常感谢任何帮助。

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. 您应该在宏中创建一个contentpicker类型参数(例如,名为“source”),并使用此参数的值作为容器节点的ID而不是currentPage。 I often use that trick, and it works perfectly, and allow you to change the node in your admin backoffice. 我经常使用这个技巧,它工作得很好,并允许您更改管理后台中的节点。

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. 要创建此节点,可以使用web.config中的键添加其ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM