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
Hello guys!
I have this razor script for my navigation:
@inherits umbraco.MacroEngines.DynamicNodeContext
@{ @*Get the root of the website *@ var root = Model.AncestorOrSelf(1);}<ul class="navigation_items" id="Navigation"> <li class="What to write here?"> <a href="/">Home</a> </li> @foreach (var page in root.Children.Where("Visible")) { <li class="@page.IsAncestorOrSelf(Model, "current_item", "")"> <a href="@page.Url">@page.Name</a> </li> }</ul>
How do I make the "Home" list item the class "current_item" when I am in the root?
Thank you! ^^
Try something like this
string state = Model.NodeTypeAlias == "DocTypeA"? "class=current_item":"";<li @state"> <a href="/">Home</a> </li>
Hmm, I cannot figure it out...
Hi Jens,
Something like this should do it for you.
@inherits umbraco.MacroEngines.DynamicNodeContext@{ @*Get the root of the website *@ var root = Model.AncestorOrSelf(1);}<ul class="navigation_items" id="Navigation"> @{ var homeActive = ""; } @if(root.Id == Model.Id){ homeActive = "current_item"; } <li class="@homeActive> <a href="@root.Url">@root.Name</a> </li> @foreach (var page in root.Children.Where("Visible")) { <li class="@page.IsAncestorOrSelf(Model, "current_item", "")"> <a href="@page.Url">@page.Name</a> </li> }</ul>
And you donĀ“t need to hardcode the URL and name of the frontpage item. You can use the @root.Url to get the URL and @root.Name to get the name.
/Dennis
Thank you so much!
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Highlight homepage when in root
Hello guys!
I have this razor script for my navigation:
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
@*Get the root of the website *@
var root = Model.AncestorOrSelf(1);
}
<ul class="navigation_items" id="Navigation">
<li class="What to write here?">
<a href="/">Home</a>
</li>
@foreach (var page in root.Children.Where("Visible"))
{
<li class="@page.IsAncestorOrSelf(Model, "current_item", "")">
<a href="@page.Url">@page.Name</a>
</li>
}
</ul>
How do I make the "Home" list item the class "current_item" when I am in the root?
Thank you! ^^
Try something like this
Hmm, I cannot figure it out...
Hi Jens,
Something like this should do it for you.
And you donĀ“t need to hardcode the URL and name of the frontpage item. You can use the @root.Url to get the URL and @root.Name to get the name.
/Dennis
Thank you so much!
is working on a reply...