Umbraco Macro Referenced Root 但在重定位后现在已损坏

Umbraco Macro Referenced Root But is now Broken After Relocation

我在 Umbraco 中按照以下步骤在我的内容节点中添加了文件夹结构。

Step 1

Create a new Document Type called Content Folder.

Go to Settings > Document Types > click on the 3 dots > Create. Give it the name Content Folder. As icon select the folder icon Add a new property Redirect with alias umbracoRedirect with type Content Picker Save changes The built-in property umbracoRedirect is used to redirect one node to another using its id. So for each folder set this property to the first child page.

Step 2

Allow your child node types in this folder.

Go to the structure tab of your Content Folder property Check the child types that you want to allow under this folder Save changes

Step 3

Allow this folder under your root Home node.

Go to the structure tab of your Home root property Check the ContentFoldertype to allow as a child Save changes

Step 4

Add you folder structure and add pages.

Go to your content Add a new folder under your root node of type Content Folder Give it the name HQ Add a new page called A that's allowed under your folder In your HQ set the Redirect property to your first A page Do this for all your folders and pages Save changes and publish

这行得通,但是我的页面中有以下宏,它显示了我所在节点的子节点。由于我将它们放在根目录中,现在我已将它们移动到子文件夹中,所以所有列表都高于 1 级他们应该是(因为当前节点低1级。

在下面的结构中,我有 2 个单独的菜单,其中一个显示在您是在章节页面还是章节页面上。在给定章节中,显示该章节中所有章节的列表。所以对于第 1 章,它将显示 1.1 和 1.2。第二个菜单位于同一章节的部分和故事页面上,并仅显示该部分中的故事,因此如果我在第 1.1 部分页面上,它将显示故事 1.1.1、1.1.2 和 1.1.3

My Structure Is Like This

    Root
    -Team 1 (Folders)
    --Level 1 (Chapters)
    ---Level 1.1 (Sections)
    ----Level 1.1.1 (Stories)
    ----Level 1.1.2 (Stories)
    ----Level 1.1.3 (Stories)
    ---Level 1.2 (Sections)
    ----Level 1.2.1 (Stories)
    ----Level 1.2.2 (Stories)
    ----Level 1.2.3 (Stories)
    --Level 2
    ---Level 2.1
    ----Level 2.1.1
    --Level 3
    --Level 4
    ---Level 4.1
    ----Level 4.1.1
    -Team 2 Folder
    -Team 3 Folder
<umbraco:Macro  runat="server" language="cshtml"> @inherits umbraco.MacroEngines.DynamicNodeContext

  @*
  Macro to display child pages below the root page of a standard website.
  Also highlights the current active page/section in the navigation with
  the css class "current". 
  *@

  @{ 
  @* Get the root of the website *@
  var root = Model.AncestorOrSelf(1);
  }
  <ul>
    <li>Chapter<br>
      Sections
      <ul>
        @foreach (var page in root.Children.Where("Visible"))
        {
        <li class="@page.IsAncestorOrSelf(Model, "current", "")"> <a href="@page.Url">@page.Name</a> </li>
        }
      </ul>
    </li>
  </ul>
</umbraco:Macro>

我想知道如何让我的宏再次工作并引用正确的节点。

编辑

我也有这个代码来显示第二级节点

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
<xsl:stylesheet 
    version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:msxml="urn:schemas-microsoft-com:xslt" 
    xmlns:umbraco.library="urn:umbraco.library" xmlns:Examine="urn:Examine" 
    exclude-result-prefixes="msxml umbraco.library Examine ">

<xsl:output method="xml" omit-xml-declaration="yes" />

<xsl:param name="currentPage"/>

<!-- Input the documenttype you want here -->
<xsl:variable name="level" select="2"/>
        <xsl:variable name="startNode" select="$currentPage/ancestor-or-self::*[@level = $level]" />
<xsl:variable name="nodesToShow" select="$startNode/*[@isDoc][not(umbracoNaviHide = 1)]" />

<xsl:template match="/">

<!-- The fun starts here -->
<xsl:if test="$nodesToShow">
    <img src="/media/1133/actheader2.png" alt="Activities in this Section" class="acttitle" />
</xsl:if>
    <ul>
<xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']">
<li>
   <xsl:attribute name="class">
        <xsl:if test="contains(activityextras,'Video')">Video</xsl:if>
        <xsl:if test="contains(activityextras,'Scripted')">Scripted</xsl:if>
        </xsl:attribute>

   <a href="{umbraco.library:NiceUrl(@id)}">
      <xsl:value-of select="@nodeName" />
   </a>
</li>
</xsl:for-each>
</ul>

</xsl:template>

</xsl:stylesheet>

此处部分代码:

var root = Model.AncestorOrSelf(1);

获取级别 1 的页面,该页面将始终是主页。如果文件夹现在总是在第二级,你应该可以将其更改为:

var root = Model.AncestorOrSelf(2);

只要您在该文件夹下,就应该可以找到该文件夹​​。如果您可能有嵌套文件夹,则需要进行进一步的更改。