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

标签 javascript node.js xslt macros umbraco

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

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

虽然有效,但是我的页面中有以下宏,它显示了我所在 Node 的子 Node 。由于我将它们放在根目录中,现在我已将它们移动到子文件夹中,所有列表都比它们应有的高 1 级是(因为当前 Node 低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>

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

编辑

我也有这段代码来显示二级 Node

<?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);

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

关于javascript - Umbraco Macro Referenced Root 但在重定位后现在已损坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31598794/

相关文章:

javascript - Google Search Appliance/Mini 可以输出 JSON/JSONP 吗?

javascript - 根据带有下划线的数组对对象进行排序

eclipse - 由于 Xalan 的 (XSLT) 安全处理功能,Ant <junitreport> 失败

javascript - 单击时获取动态创建元素的 top 值或 marginTop 值

node.js - 将子目录文件部署到nodejitsu

mysql - 如何在 node.js 中将特定范围的端口重定向到端口 80

node.js - 部署后如何重启webjobs?

xml - Docbook XML 到 PDF,没有 'ő' 和 'ű' 字符

javascript - 外部 js 文件中的更新未反射(reflect)为事件触发

javascript - iOS Safari 的 iframe 无法获取设备方向和运动事件