Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi Guys,
I have a main navigation with 2 level (drop down menu). What am trying to do is something like when clicking on the 2nd level link navi i get the first level showing this section is selectet or (current) in my case.
My XSLT looks like this
<xsl:if test="$currentPage/ancestor-or-self::*[@isDoc]/@id = current()/@id"> <xsl:text> current</xsl:text> </xsl:if>
And Razor
<li> { <a href="@page.Url" class="@Library.If(page.Id == Model.Id, "current", "")">@page.Name</a> } <!-- (2nd Level or drop down--> @if (page.children.Where("Visible").Count() > 0) { <ul> @foreach (var childPage in page.Children.Where("Visible")) { <li><a href="@childPage.Url">@childPage.Name</a></li> } </ul> } </li>
Any help on this?
//fuji
Here's an example of how I do a top level nav using the IsAncestorOrSelf method of a DynamicNode. It should help you:
@inherits umbraco.MacroEngines.DynamicNodeContext @using umbraco.MacroEngines; @{ var pages = Model.AncestorOrSelf(1).Children.Where("Visible && template > 0"); const string selectedClass = " class=\"current\""; bool hasSubNav = true; <ul id="nav"> <[email protected](Model.NodeTypeAlias == "Home", selectedClass)> <a href="/">Home</a> </li> @if (pages.Count() > 0) { foreach (dynamic page in pages) { <[email protected](page.IsAncestorOrSelf(Model), selectedClass)> <a href="@page.Url">@page.Name</a> @if (hasSubNav) { @RenderSubNav(page, selectedClass) } </li> } } </ul> } @helper RenderSubNav(dynamic parent, string selectedClass) { var pages = parent.Children.Where("Visible && template > 0"); if (pages.Count() > 0) { <ul> @foreach (dynamic page in pages) { <[email protected](Model.Id == page.Id, selectedClass)> <a href="@page.Url">@page.Name</a> </li> } </ul> } }
Hi Dan,
Thanks for the response, ill give this a try and let you know.
I try to understand and at same modify my razor file but on saving am getting this error message.
No overload for method 'If' takes 2 arguments
I even copy > paste your code but without success having the same error.
Hi Fuji,
My code, as pasted, definitely works in Umbraco 4.7.1
Are you using 4.7.1 or higher, because I think Library.If method was only introduced in that version?
If you are, could you post your script as it must be something in that?
Dan am running on V4.7.0.
I guess that what giving errors??
Dan i just overwrite my umbraco.MacroEngines.dll. I think it should get me working .
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
Converting XSLT Navi toRazor
Hi Guys,
I have a main navigation with 2 level (drop down menu). What am trying to do is something like when clicking on the 2nd level link navi i get the first level showing this section is selectet or (current) in my case.
My XSLT looks like this
And Razor
Any help on this?
//fuji
Here's an example of how I do a top level nav using the IsAncestorOrSelf method of a DynamicNode. It should help you:
Hi Dan,
Thanks for the response, ill give this a try and let you know.
//fuji
Hi Dan,
I try to understand and at same modify my razor file but on saving am getting this error message.
No overload for method 'If' takes 2 arguments
I even copy > paste your code but without success having the same error.
//fuji
Hi Fuji,
My code, as pasted, definitely works in Umbraco 4.7.1
Are you using 4.7.1 or higher, because I think Library.If method was only introduced in that version?
If you are, could you post your script as it must be something in that?
Dan am running on V4.7.0.
I guess that what giving errors??
Dan i just overwrite my umbraco.MacroEngines.dll.
I think it should get me working .
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.