MegaNav: Getting context while rendering navigation
Hi all,
I consider myself an expert in rendering navigations using XSLT, and using Razor I've come quite far as well - as long as they're based on the Content structure it's no problem.
Now I have a site which is using Cogworks' MegaNav package for the navigation, and here's where I get stuck:
I need to add a class on a top level item if the currently rendered page is somewhere below it. Easy when using the content structure, but when using MegaNav, I don't have access to any Ancestor/Descendant helper methods that works within the structure built by the editor. At least not as far as I can tell...
I have not used MegaNav myself, but it seems like the MeganavItem class has a Content property, where the node of the item is stored (if not external).
I forgot the original problem again: Because the Meganav structure can be totally different from the actual content structure, I really can't use IsAncestorOf() etc.
E.g.:
Even with a simple content structure like this:
Home
- About
- Products
I can create a Meganav structure that looks like this:
Our company
- Who we are (link to /about/)
Our products
- All of them (link to /products/)
When rendering the Products page, I need to set a .currentpath class (or similar) on the Our products item and I can't get that info without traversing the actual Meganav model...
MegaNav: Getting context while rendering navigation
Hi all,
I consider myself an expert in rendering navigations using XSLT, and using Razor I've come quite far as well - as long as they're based on the Content structure it's no problem.
Now I have a site which is using Cogworks' MegaNav package for the navigation, and here's where I get stuck:
I need to add a class on a top level item if the currently rendered page is somewhere below it. Easy when using the content structure, but when using MegaNav, I don't have access to any Ancestor/Descendant helper methods that works within the structure built by the editor. At least not as far as I can tell...
How do you handle this scenario (if at all)?
/Chriztian
Hi Chriztian
I have not used MegaNav myself, but it seems like the MeganavItem class has a Content property, where the node of the item is stored (if not external).
So assuming you do something like this:
You should be able to test for ancestors like (Model is the current page rendered)
Brilliant, Søren — had forgot about the
Is*
helpers, actually.Will try it out right away.
/Chriztian
Ah, but no :(
I forgot the original problem again: Because the Meganav structure can be totally different from the actual content structure, I really can't use
IsAncestorOf()
etc.E.g.:
Even with a simple content structure like this:
I can create a Meganav structure that looks like this:
When rendering the Products page, I need to set a
.currentpath
class (or similar) on the Our products item and I can't get that info without traversing the actual Meganav model.../Chriztian
How about this?
This one gets all descendants id's of
item
, and then checks if the current node's id (Model.Id) is one of them.It's works!
Never heard of
SelectRecursive()
before - but it's perfect here :)Thanks a ton!
(Thankfully, the Meganav allows setting a max. level, so I don't think there will be any performance concerns with this.)
/Chriztian
Haha, I never used it before - but Intellisense is your friend :)
is working on a reply...