Umbraco Razor Simple Alternative Subnav
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
var startLevel = String.IsNullOrEmpty(Parameter.Level) ? 2 : int.Parse(Parameter.StartLevel);
var finishLevel = String.IsNullOrEmpty(Parameter.Level) ? 8 : int.Parse(Parameter.FinishLevel);
var parent = Model.AncestorOrSelf(startLevel);
if (parent != null) { @traverse(parent,startLevel,finishLevel) ; }
}
@helper traverse(dynamic parent,int startLevel,int finishLevel)
{
foreach (var node in parent.Children.Where("Visible"))
{
var selected = Array.IndexOf(Model.Path.Split(','), node.Id.ToString()) >= 0 ? " id=\"current\"" : "";
<li >
<a href="@node.Url">@node.Name</a>
@if (selected!=""&&@node.Level<=finishLevel) { @traverse(node,startLevel,finishLevel); }
</li>
}
}
@{
var startLevel = String.IsNullOrEmpty(Parameter.Level) ? 2 : int.Parse(Parameter.StartLevel);
var finishLevel = String.IsNullOrEmpty(Parameter.Level) ? 8 : int.Parse(Parameter.FinishLevel);
var parent = Model.AncestorOrSelf(startLevel);
if (parent != null) { @traverse(parent,startLevel,finishLevel) ; }
}
@helper traverse(dynamic parent,int startLevel,int finishLevel)
{
foreach (var node in parent.Children.Where("Visible"))
{
var selected = Array.IndexOf(Model.Path.Split(','), node.Id.ToString()) >= 0 ? " id=\"current\"" : "";
<li >
<a href="@node.Url">@node.Name</a>
@if (selected!=""&&@node.Level<=finishLevel) { @traverse(node,startLevel,finishLevel); }
</li>
}
}
Comments
Post a Comment