2014-01-06 34 views
0

为了说明我的问题比较容易,请先看这些照片,如何在Umbraco CMS中关闭显示所选主菜单项的子项目?

enter image description here

在我的模板,我已经配置了顶部导航,但问题是,我试图让新的菜单项将被称为“新闻'的事情是,我不希望每一个我将发布的99个新闻项目(在接下来的两个月内)都被自动提供为'新闻'下的sumbenu子项目。

正如我注意到,大部分配置是在“umbTopNavigation.xslt”

]> 
xmlns:msxml="urn:schemas-microsoft-com:xslt" 
xmlns:umbraco.library="urn:umbraco.library" 
exclude-result-prefixes="msxml umbraco.library"> 
<xsl:output method="xml" omit-xml-declaration="yes" /> 

<xsl:param name="currentPage"/> 

<!-- Input the documenttype you want here --> 
<xsl:variable name="level" select="1"/> 

<xsl:template match="/"> 

    <ul id="topNavigation"> 
    <li class="home"> 
    <xsl:if test="$currentPage/@id = $currentPage/ancestor-or-self::* [@level=$level]/@id"> 
     <xsl:attribute name="class">home current</xsl:attribute> 
    </xsl:if> 
    <a href="/">Home</a> 
    </li> 
    <xsl:for-each select="$currentPage/ancestor-or-self::* [@level=$level]/* [@isDoc and string(umbracoNaviHide) != '1']"> <li> 
<xsl:if test="@id = $currentPage/@id"> 
    <xsl:attribute name="class">current</xsl:attribute> 
    </xsl:if> 
<a class="navigation" href="{umbraco.library:NiceUrl(@id)}"> 
    <span><xsl:value-of select="@nodeName"/></span> 
</a> </li> 
    </xsl:for-each> </ul> 

</xsl:template> 

,但我想不出到底是什么,我需要改变? 任何帮助表示感谢,并提前致谢! MC2012 一是宏观

<?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" 
    exclude-result-prefixes="msxml umbraco.library"> 

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

<xsl:param name="currentPage"/> 

<xsl:template match="/"> 

    <xsl:variable name="items" select="$currentPage/ancestor-or-self::* [@isDoc and @level = 2]/* [@isDoc and string(umbracoNaviHide) != '1']"/> 

<!-- The fun starts here --> 

<xsl:if test="count($items) &gt; 0"> 
<ul> 
<xsl:for-each select="$items"> 
    <li> 
    <a href="{umbraco.library:NiceUrl(@id)}"> 
     <xsl:value-of select="@nodeName"/> 
    </a> 
    </li> 
</xsl:for-each> 
</ul> 
    </xsl:if> 

</xsl:template> 

</xsl:stylesheet> 

第二个宏

<?xml version="1.0" encoding="utf-8" ?> 
<xsl:stylesheet 
    version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:umbraco.library="urn:umbraco.library" 
    exclude-result-prefixes="umbraco.library" 
> 

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

    <xsl:param name="currentPage" /> 

    <!-- Specify level of the top node for a language (usually 1) --> 
    <xsl:variable name="level" select="1" /> 

    <!-- Grab the top node --> 
    <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = $level]" /> 

    <xsl:template match="/"> 
     <ul class="menu"> 
      <!-- Create the Home link --> 
      <li> 
       <xsl:if test="$currentPage/@id = $siteRoot/@id"> 
        <xsl:attribute name="class">sel</xsl:attribute> 
       </xsl:if> 
       <a href="{umbraco.library:NiceUrl($siteRoot/@id)}"> 
        <xsl:value-of select="$siteRoot/@nodeName" /> 
       </a> 
      </li> 
      <!-- Process all children of $siteRoot (if any) --> 
      <xsl:apply-templates select="$siteRoot/*[@isDoc][not(umbracoNaviHide = 1)]" /> 
     </ul> 
    </xsl:template> 

    <!-- Generic template for all nav links --> 
    <xsl:template match="*[@isDoc]"> 
     <li> 
      <xsl:if test="@id = $currentPage/@id"> 
       <xsl:attribute name="class">sel</xsl:attribute> 
      </xsl:if> 
      <a href="{umbraco.library:NiceUrl(@id)}"> 
       <xsl:value-of select="@nodeName" /> 
      </a> 
      <!-- Render sub menu if necessary --> 
      <xsl:call-template name="submenu" /> 
     </li> 
    </xsl:template> 

    <!-- Template for Inactive links --> 
    <xsl:template match="*[@isDoc][umbracoNaviInactive = 1]"> 
     <li> 
      <xsl:if test="@id = $currentPage/@id"> 
       <xsl:attribute name="class">sel</xsl:attribute> 
      </xsl:if> 
      <span> 
       <xsl:value-of select="@nodeName" /> 
      </span> 
      <!-- Submenu? --> 
      <xsl:call-template name="submenu" /> 
     </li> 
    </xsl:template> 

    <!-- Template checking for, and processing any submenu --> 
    <xsl:template name="submenu"> 
     <xsl:variable name="subPages" select="*[@isDoc][not(umbracoNaviHide = 1)]" /> 
     <xsl:if test="$subPages"> 
      <ul> 
       <xsl:apply-templates select="$subPages" /> 
      </ul> 
     </xsl:if> 
    </xsl:template> 

</xsl:stylesheet> 
+0

你确定你这里列出了正确的宏?看起来上面的代码只支持单层导航,而不是多层导航。 –

+0

Hello Carl,看起来我在模板上发现了两个宏。 – MC2012

+0

我编辑了我的第一个问题,在问题的底部,您会发现第一个和第二个宏的代码。谢谢你,MC2012 – MC2012

回答

0

好了 - 你有两个选择。快速入门或完整的解决方案。

快速黑客是更新第二个宏其中subnav被调用,并排除subnav被称为它的新闻页面(你可以包括在这里的其他页面太)

在这个例子中,我使用节点ID 1107作为新闻页面的ID,但您需要使用您的实际新闻页面ID进行更新。

<?xml version="1.0" encoding="utf-8" ?> 
<xsl:stylesheet 
    version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:umbraco.library="urn:umbraco.library" 
    exclude-result-prefixes="umbraco.library" 
> 

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

    <xsl:param name="currentPage" /> 

    <!-- Specify level of the top node for a language (usually 1) --> 
    <xsl:variable name="level" select="1" /> 

    <!-- Grab the top node --> 
    <xsl:variable name="siteRoot" select="$currentPage/ancestor-or-self::*[@level = $level]" /> 

    <xsl:template match="/"> 
     <ul class="menu"> 
      <!-- Create the Home link --> 
      <li> 
       <xsl:if test="$currentPage/@id = $siteRoot/@id"> 
        <xsl:attribute name="class">sel</xsl:attribute> 
       </xsl:if> 
       <a href="{umbraco.library:NiceUrl($siteRoot/@id)}"> 
        <xsl:value-of select="$siteRoot/@nodeName" /> 
       </a> 
      </li> 
      <!-- Process all children of $siteRoot (if any) --> 
      <xsl:apply-templates select="$siteRoot/*[@isDoc][not(umbracoNaviHide = 1)]" /> 
     </ul> 
    </xsl:template> 

    <!-- Generic template for all nav links --> 
    <xsl:template match="*[@isDoc]"> 
     <li> 
      <xsl:if test="@id = $currentPage/@id"> 
       <xsl:attribute name="class">sel</xsl:attribute> 
      </xsl:if> 
      <a href="{umbraco.library:NiceUrl(@id)}"> 
       <xsl:value-of select="@nodeName" /> 
      </a> 
      <!-- Render sub menu if necessary excluding the news pages --> 
      <xsl:if test="not(@id=1107)"> 
       <xsl:call-template name="submenu" /> 
      </xsl:if> 
     </li> 
    </xsl:template> 

    <!-- Template for Inactive links --> 
    <xsl:template match="*[@isDoc][umbracoNaviInactive = 1]"> 
     <li> 
      <xsl:if test="@id = $currentPage/@id"> 
       <xsl:attribute name="class">sel</xsl:attribute> 
      </xsl:if> 
      <span> 
       <xsl:value-of select="@nodeName" /> 
      </span> 
      <!-- Submenu? --> 
      <xsl:call-template name="submenu" /> 
     </li> 
    </xsl:template> 

    <!-- Template checking for, and processing any submenu --> 
    <xsl:template name="submenu"> 
     <xsl:variable name="subPages" select="*[@isDoc][not(umbracoNaviHide = 1)]" /> 
     <xsl:if test="$subPages"> 
      <ul> 
       <xsl:apply-templates select="$subPages" /> 
      </ul> 
     </xsl:if> 
    </xsl:template> 

</xsl:stylesheet> 

正确的方式做这将是一个属性添加到您的文档类型包括物业说没有列出的儿童或者类似的,然后测试,在XSLT,但这是一个更涉及修复,为此,我建议您多阅读一下XSLT的工作原理。让我知道如果你想要去的这条路线,并有大量的资源,我可以指导您

感谢,

+0

如果这个答案是有帮助的,我会很感激你将此标记为答案。如果不是 - 不用担心 –

相关问题