I got a snippet off the forums on how to build a drop down menu.How do I deal with any of the UmbracoNaviHide propertie in the menu. So if any of level 1 or level 2 properties are tagged with umbracoNaviHide or another property. How would that work? My original XSLT menu is below the Razor script.I am trying to convert to Razor. It is a bit large.
<msxml:script implements-prefix="scripts" language="C#"> <msxml:assembly name="umbraco"/> <msxml:using namespace="umbraco"/> <![CDATA[ public bool isNull(string s1) { return String.IsNullOrEmpty(s1); } ]]> </msxml:script> <xsl:variable name="var_false" select="false()"/> <xsl:variable name="var_true" select="true()"/> <!--Commented out currentPage due to xsl-include conflicts with other xslt templates. Use umbraco.library:GetXmlNodeCurrent() inplace of any currentPage params--> <!--<xsl:param name="currentPage"/>-->
<!-- Input the documenttype you want here --> <!-- Typically '1' for topnavigtaion and '2' for 2nd level --> <!-- Use div elements around this macro combined with css --> <!-- for styling the navigation --> <!-- update this variable on how deep your site map should be --> <xsl:variable name="maxLevelForSitemap" select="1"/> <xsl:template match="/" name="mainDropMenu"> <xsl:choose> <xsl:when test="umbraco.library:GetXmlNodeCurrent()/ancestor-or-self::* [@isDoc]"> <xsl:call-template name="makeNav"> <xsl:with-param name="parent" select="umbraco.library:GetXmlNodeCurrent()/ancestor-or-self::* [@level=1 and @isDoc]"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:call-template name="makeNav"> <xsl:with-param name="parent" select="umbraco.library:GetXmlNodeCurrent()/ancestor-or-self::* [@level=1 and @isDoc]"/> </xsl:call-template> </xsl:otherwise> </xsl:choose>
New to Razor. Dropdown menu. Umbraco Navi hide
I got a snippet off the forums on how to build a drop down menu.How do I deal with any of the UmbracoNaviHide propertie in the menu. So if any of level 1 or level 2 properties are tagged with umbracoNaviHide or another property. How would that work? My original XSLT menu is below the Razor script.I am trying to convert to Razor. It is a bit large.
<ul id="mainNav">
<li><a href="/">Home</a> </li>
@foreach (var page in @Model.AncestorOrSelf(1).Children)
{
string style = "";
if (Model.Id == page.Id) { style = "class=\"selected\""; }
<li>
<a href="@page.Url" @Html.Raw(style)>@page.Name</a>
@if (page.Childen != null && page.Children.Count() > 0)
{
<ul class="subNavFirst">
@foreach (dynamic secondPage in page.Children)
{
<li>
<a href="@secondPage.Url">@secondPage.Name</a>
</li>
}
</ul>
}
</li>
}
</ul>
Trying to convert this to Razor.
<msxml:script implements-prefix="scripts" language="C#">
<msxml:assembly name="umbraco"/>
<msxml:using namespace="umbraco"/>
<![CDATA[
public bool isNull(string s1)
{
return String.IsNullOrEmpty(s1);
}
]]>
</msxml:script>
<xsl:variable name="var_false" select="false()"/>
<xsl:variable name="var_true" select="true()"/>
<!--Commented out currentPage due to xsl-include conflicts with other xslt templates.
Use umbraco.library:GetXmlNodeCurrent() inplace of any currentPage params-->
<!--<xsl:param name="currentPage"/>-->
<!-- Input the documenttype you want here -->
<!-- Typically '1' for topnavigtaion and '2' for 2nd level -->
<!-- Use div elements around this macro combined with css -->
<!-- for styling the navigation -->
<!-- update this variable on how deep your site map should be -->
<xsl:variable name="maxLevelForSitemap" select="1"/>
<xsl:template match="/" name="mainDropMenu">
<xsl:choose>
<xsl:when test="umbraco.library:GetXmlNodeCurrent()/ancestor-or-self::* [@isDoc]">
<xsl:call-template name="makeNav">
<xsl:with-param name="parent" select="umbraco.library:GetXmlNodeCurrent()/ancestor-or-self::* [@level=1 and @isDoc]"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="makeNav">
<xsl:with-param name="parent" select="umbraco.library:GetXmlNodeCurrent()/ancestor-or-self::* [@level=1 and @isDoc]"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="makeNav">
<xsl:param name="parent"/>
<ul id="mainNav">
<xsl:for-each select="$parent/* [@isDoc and string(umbracoNaviHide) != '1']">
<li>
<xsl:if test="umbraco.library:GetXmlNodeCurrent()/ancestor-or-self::*/@id = current()/@id">
<xsl:attribute name="class">selected</xsl:attribute>
</xsl:if>
<xsl:call-template name="firstSubCategory">
<xsl:with-param name="myNode" select="."/>
</xsl:call-template>
<xsl:if test="count(./* [@isDoc and string(umbracoNaviHide) != '1']) > 0">
<ul class="subNavFirst">
<xsl:for-each select="current()/* [@isDoc and string(umbracoNaviHide) != '1']">
<li>
<xsl:call-template name="firstSubCategory">
<xsl:with-param name="myNode" select="."/>
</xsl:call-template>
<!-- new for-each loop for children of parents here -->
<xsl:if test="count(current()/* [@isDoc and string(umbracoNaviHide) != '1']) > 0">
<xsl:if test="string(hideChildPagesFromMainNav) != '1'">
<ul class="subNavSecond">
<xsl:for-each select="current()/* [@isDoc and string(umbracoNaviHide) != '1']">
<li>
<xsl:call-template name="secondSubCategory">
<xsl:with-param name="myNode" select="."/>
</xsl:call-template>
</li>
</xsl:for-each>
</ul>
</xsl:if>
</xsl:if>
</li>
</xsl:for-each>
<li class="subNavBottom">
<img src="/media/1944/MenuBgShadowBottom.png" alt=""/>
</li>
</ul>
</xsl:if>
</li>
</xsl:for-each>
</ul>
</xsl:template>
<xsl:template name="firstSubCategory">
<xsl:param name="myNode"/>
<xsl:choose>
<xsl:when test="$myNode/@nodeType = 1053">
<a href="{$myNode/redirectURL}">
<xsl:value-of select="$myNode/@nodeName"/>
</a>
</xsl:when>
<xsl:otherwise>
<a href="{umbraco.library:NiceUrl($myNode/@id)}">
<xsl:if test="umbraco.library:GetXmlNodeCurrent()/ancestor-or-self::*/@id = $myNode/@id">
<xsl:attribute name="class">current_subFirst</xsl:attribute>
</xsl:if>
<xsl:call-template name="NavName">
<xsl:with-param name="myNode" select="."/>
</xsl:call-template>
</a>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="secondSubCategory">
<xsl:param name="myNode"/>
<a href="{umbraco.library:NiceUrl($myNode/@id)}">
<xsl:if test="umbraco.library:GetXmlNodeCurrent()/ancestor-or-self::*/@id = $myNode/@id">
<xsl:attribute name="class">current_subSecond</xsl:attribute>
</xsl:if>
<xsl:call-template name="NavName">
<xsl:with-param name="myNode" select="."/>
</xsl:call-template>
</a>
</xsl:template>
<xsl:template name="NavName">
<xsl:param name="myNode"/>
<xsl:choose>
<xsl:when test="scripts:isNull($myNode/alternateNavigationName) = $var_false">
<xsl:value-of select="$myNode/alternateNavigationName"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$myNode/@nodeName"/>
</xsl:otherwise>
</xsl:choose>
Does this help?
is working on a reply...