I have this menu that works almost fine. It givs me all the items <li></li> but I need it to not write the <ul> tag if there is now submenues. I will send you the code, maybe it willmake more sense :-)
I am total new to cshtml kode, I dont even know if the question belongs ind this kategorie. Hope you will help me anyway :-)
@using umbraco.MacroEngines; @inherits umbraco.MacroEngines.DynamicNodeContext @{ var level = String.IsNullOrEmpty(Parameter.Level) ? 2 : int.Parse(Parameter.Level); var parent = @Model.AncestorOrSelf(level);
if (parent != null) { <ul class="subNavMenu"> @foreach (var item in parent.Children) { var selected = Array.IndexOf(Model.Path.Split(','), item.Id.ToString()) >= 0 ? " class=\"selected\"" : ""; if (item.Visible) { <[email protected](selected)> <a href="@item.Url">@item.Name</a> </li> } else if(item.NodeTypeAlias == "MenuPunkt") { var children = item.ChildrenAsList;
if (children.Count > 0) { var menuItem = children[0]; <[email protected](selected)> <a href="@menuItem.Url">@item.Name</a> </li> } } } </ul> } }
submenu problem in cshtml file
I have this menu that works almost fine. It givs me all the items <li></li> but I need it to not write the <ul> tag if there is now submenues. I will send you the code, maybe it will make more sense :-)
I am total new to cshtml kode, I dont even know if the question belongs ind this kategorie. Hope you will help me anyway :-)
@using umbraco.MacroEngines;
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
var level = String.IsNullOrEmpty(Parameter.Level) ? 2 : int.Parse(Parameter.Level);
var parent = @Model.AncestorOrSelf(level);
if (parent != null)
{
<ul class="subNavMenu">
@foreach (var item in parent.Children)
{
var selected = Array.IndexOf(Model.Path.Split(','), item.Id.ToString()) >= 0 ? " class=\"selected\"" : "";
if (item.Visible)
{
<[email protected](selected)>
<a href="@item.Url">@item.Name</a>
</li>
}
else if(item.NodeTypeAlias == "MenuPunkt")
{
var children = item.ChildrenAsList;
if (children.Count > 0)
{
var menuItem = children[0];
<[email protected](selected)>
<a href="@menuItem.Url">@item.Name</a>
</li>
}
}
}
</ul>
}
}
Hi Kate,
If you want the submenu to display childnodes from level 2 you should be able to reduce your razor code to this:
... Unless you have reson to check if the NodeTypeAlias is a "MenuPunkt". It depens on how you organize your content...?
is working on a reply...