I need your help to something I think is really simple. Just not for me. :-)
In the code below I have made a TopNavigation that works. But as you can see then the "Home" menu item is hardcoded / static and I really want it to do the same as the submenu. When I create the submenu I use "Foreach" because there will be more than one submenu.
My question is - How can I make "Home" to be dynamic instead of hardcoded / static without the use of "Foreach" because it is only one menu item.?
Please add to the code below if you have the solution.
I may have misunderstood the question but from the sound of things you want to display the homepage of the site but without hard coding it. I'd assume this is so that you can pull through the correct name for the homepage. The way in which I do this is using the following code snippet:
As your homepage should be the first node in your document tree, this will select it so that you can use it how you wish.
The way is works is, Model.Content selects the current page that you are on. AncestorsOrSelf(1) will select any ancestors of the current page that are on level 1. If the page itself is on level one it will also be selected. At this point you have an IEnumerable
You can then use :
@homepage.Name
and
@homepage.Url
to access the relevant properties needed to create the link.
That worked perfectly. But is there a way to use "@homepage.menuName" instead of "@homepage.Name". menuName is something I have made, so that you can change the name from e.g. a content tab and also use letters like "æøå".
Topnavigation problem
Hello everybody
I need your help to something I think is really simple. Just not for me. :-)
In the code below I have made a TopNavigation that works. But as you can see then the "Home" menu item is hardcoded / static and I really want it to do the same as the submenu. When I create the submenu I use "Foreach" because there will be more than one submenu.
My question is - How can I make "Home" to be dynamic instead of hardcoded / static without the use of "Foreach" because it is only one menu item.?
Please add to the code below if you have the solution.
Thank you in advance!
//René
I may have misunderstood the question but from the sound of things you want to display the homepage of the site but without hard coding it. I'd assume this is so that you can pull through the correct name for the homepage. The way in which I do this is using the following code snippet:
As your homepage should be the first node in your document tree, this will select it so that you can use it how you wish.
The way is works is, Model.Content selects the current page that you are on. AncestorsOrSelf(1) will select any ancestors of the current page that are on level 1. If the page itself is on level one it will also be selected. At this point you have an IEnumerable
You can then use :
and
to access the relevant properties needed to create the link.
Hi Jason
That worked perfectly. But is there a way to use "@homepage.menuName" instead of "@homepage.Name". menuName is something I have made, so that you can change the name from e.g. a content tab and also use letters like "æøå".
Thanks!
//René
Hi,
You can simply use @homepage.GetPropertyValue("menuName")
Matt
Thanks Matt
That worked like a charm. :-)
// René
is working on a reply...