I have a navigation bar, which has some links in it. I am using cultures (Danish and English), and I would like to generate my navigation links as much as possible.
A problem I have is: I don't want to loop over each page, as I don't want some of the pages to appear there.
I want to set an class="active" on the currently active page (or sub page). So if I have a news page, it should make it active. If I read a news article, it should also be active. The URL is /news/ and also /news/news-article-1 so the article is indeed in the correct spot.
How would I achieve something like this?
Requirements:
No foreach loop (unless I can tell it specifically which ones I don't want)
Set an class="active" on the active page
Be able to insert my own menu item (like a link to an external page)
If you add a property to your document types called umbracoNaviHide of type True/False and then check the box on the pages you don't want to display in navigation you can then do a foreach
Thanks, that could work indeed! Now I just have another question, which I hope you can help me with, because I think my page structure is messed up. In order to make your solution work, this problem needs to be solved:
When I do this, I have three links shown: News - People - Services
However, I really want to have: References - Services - News - Contact
I currently have a Master content item, which has three subitems, which has my items in it. It goes something like this:
I like this layout because I can create news under news, people under people, and services under services. Basically like models. However, I do not want my References page to have any sub items, because References does not have a model (it's just a static page).
Now here are my Document Types and Templates:
I think this is where I got it wrong, because when I go to create a new item, I select ListNews, ListPeople, or ListServices. These basically have the properties I need in order to create an item.
Do you see where I'm going at? Here's my issue: When I go to /news/ it works fine. Model.Content.Url is /news/. If I go to /references/ it shows me an empty page, but the Model.Content.Url is /.
Can you tell me what I am doing wrong? I think I got this wrong from the beginning (watching old tutorials perhaps).
Cultures and navigation
Hello!
I have a navigation bar, which has some links in it. I am using cultures (Danish and English), and I would like to generate my navigation links as much as possible.
A problem I have is: I don't want to loop over each page, as I don't want some of the pages to appear there.
I want to set an
class="active"
on the currently active page (or sub page). So if I have a news page, it should make it active. If I read a news article, it should also be active. The URL is/news/
and also/news/news-article-1
so the article is indeed in the correct spot.How would I achieve something like this?
Requirements:
class="active"
on the active pageThanks!
Hi Morten,
If you add a property to your document types called umbracoNaviHide of type True/False and then check the box on the pages you don't want to display in navigation you can then do a foreach
Where("Visible") will then only select the items that have umbracoNaviHide set to false.
This bit @(item.IsAncestorOrSelf(CurrentPage) ? "active" : null) is what I normally do to add the active class.
Hi!
Thanks, that could work indeed! Now I just have another question, which I hope you can help me with, because I think my page structure is messed up. In order to make your solution work, this problem needs to be solved:
When I do this, I have three links shown: News - People - Services
However, I really want to have: References - Services - News - Contact
I currently have a Master content item, which has three subitems, which has my items in it. It goes something like this:
I like this layout because I can create news under news, people under people, and services under services. Basically like models. However, I do not want my References page to have any sub items, because References does not have a model (it's just a static page).
Now here are my Document Types and Templates:
I think this is where I got it wrong, because when I go to create a new item, I select ListNews, ListPeople, or ListServices. These basically have the properties I need in order to create an item.
Do you see where I'm going at? Here's my issue: When I go to
/news/
it works fine.Model.Content.Url
is/news/
. If I go to/references/
it shows me an empty page, but theModel.Content.Url
is/
.Can you tell me what I am doing wrong? I think I got this wrong from the beginning (watching old tutorials perhaps).
Thanks a bunch!!
Where on the content tree is the References page? Can you also provide a wider snippet of code that is not working the way you hoped?
is working on a reply...