I've been trying to port my xslt 2nd level menu to razor. The idea is to have a menu header depending on which Document Type the current page has. Also, the menu in not nested, just a clean list of the children of 2nd level pages, and when you descend to any of these children, a list of siblings. This is what I had in xslt:
<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']"/>
@inherits RenderViewPage @using Umbraco.Cms.Web; @{var title = "";} @{if(DynamicModel.ContentType.Alias == "DocType1"){ title = "DocType1 Header"; } else if(DynamicModel.ContentType.Alias == "DocType2"){ title = "DocType2 Header"; } else { title = "Generic Header"; } } <h2>@title</h2> <ul> @foreach(var item in DynamicModel.Children) { if (@item.CurrentTemplate != null) { <li><a href="@item.Url">@item.Name</a></li> } } </ul>
My questions are: Can the If part in Razor be optimized? (Converted to a switch or a smaller expression) And, how can I get this menu to show children in the 2nd level, but siblings in the 3rd? (Using .AncestorOrSelf, I guess, but I've only got errors with that). Thanks in advance.
Umbraco 5: Razor 2nd level nav
I've been trying to port my xslt 2nd level menu to razor. The idea is to have a menu header depending on which Document Type the current page has. Also, the menu in not nested, just a clean list of the children of 2nd level pages, and when you descend to any of these children, a list of siblings. This is what I had in xslt:
And this is what I have in a Razor Partial View:
My questions are: Can the If part in Razor be optimized? (Converted to a switch or a smaller expression) And, how can I get this menu to show children in the 2nd level, but siblings in the 3rd? (Using .AncestorOrSelf, I guess, but I've only got errors with that). Thanks in advance.
is working on a reply...