Hey all, about time i got myself into Razor and l've inserted the NAVIGATION BY LEVEL razor script wihch works well except i want my home page link to appear also, currently its only page created below my home page which are appeearing.
Any ideas?
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
var level = String.IsNullOrEmpty(Parameter.Level) ? 1 : int.Parse(Parameter.Level);
var ulClass = String.IsNullOrEmpty(Parameter.UlClass) ? "" : String.Format(" class=\"{0}\"", Parameter.UlClass);
Adapt navigation by level
Hey all, about time i got myself into Razor and l've inserted the NAVIGATION BY LEVEL razor script wihch works well except i want my home page link to appear also, currently its only page created below my home page which are appeearing.
Any ideas?
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
var level = String.IsNullOrEmpty(Parameter.Level) ? 1 : int.Parse(Parameter.Level);
var ulClass = String.IsNullOrEmpty(Parameter.UlClass) ? "" : String.Format(" class=\"{0}\"", Parameter.UlClass);
var parent = @Model.AncestorOrSelf(level);
if (parent != null) {
<[email protected](ulClass)>
@foreach (var item in parent.Children.Where("Visible")) {
var selected = Array.IndexOf(Model.Path.Split(','), item.Id.ToString()) >= 0 ? " class=\"selected\"" : "";
<[email protected](selected)>
<a href="@item.Url">@item.Name</a> /
</li>
}
</ul>
}
}
Hi Stephen
I'm no Razor wizard (yet) but I think you should do something like this:
<li>
<a href="@parent.First().Url">@parent.First().Name</a>
</li>
You should place it right before the @foreach statement.
You can find more inspiration in the cheat sheet if you have not seen it already.
Hope this helps.
/Jan
Hi Stephen,
Another way round to display your Home page and get the link and highlighted whenever you are on the link you be
Here am checking if the NodeTypeAlias that is the Document Type "Home".
since am on multilingual website i have some dictionary items here for the HomeNode and HomeLang.
Hope it helps, again as Jan said in its previous post have a look at the razor cheat sheet by Peter.
//fuji
is working on a reply...