Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Carlos 338 posts 472 karma points
    Feb 01, 2012 @ 22:06
    Carlos
    0

    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><href="/">Home</a</li>
        @foreach (var page in @Model.AncestorOrSelf(1).Children)
        {
            string style "";
            if (Model.Id == page.Idstyle "class=\"selected\""}
            <li>
                <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>
                             <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']) &gt; 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']) &gt; 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">
                    <href="{$myNode/redirectURL}">
                        <xsl:value-of select="$myNode/@nodeName"/>
                    </a>
                </xsl:when>
                <xsl:otherwise>
                    <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"/>
            <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>

     


  • Amir Khan 1282 posts 2739 karma points
    Feb 14, 2012 @ 20:34
    Amir Khan
    0

    Does this help?

    @inherits umbraco.MacroEngines.DynamicNodeContext
    <ul class="sf-menu">
        <li><a href="/">Home</a> </li>
        @foreach (var page in @Model.AncestorOrSelf(1).Children.Where("Visible"))
        {
            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.Where("Visible"))
                     {
                        <li>
                             <a href="@secondPage.Url">@secondPage.Name</a>
                        </li>
                    }
                    </ul>
                }
            </li>
        }
    </ul>
Please Sign in or register to post replies

Write your reply to:

Draft