Just a quick Kentico menu solution
Thought I’d post this solution to what I would have thought was a fairly common problem with this product.
I’m using an ASP.Net CMS called Kentico CMS. It is quite good – much more friendly than some others I’ve used recently. I’ve been trying to get the CSS Menu control set up so that it will always show root pages, and also the pages beneath the current page. It wasn’t as easy as I thought.
For example:
Home
About
- Our Products
- Our Services
- Programming
- Design
Links
- Friends
Contact
In the example above, no matter where I was on the site, I wanted to see Home, About, Links, and Contact on the menu. If I was on the About page, then the Our Products and Our Services links should be shown as well. So I’m looking for the root pages and the children of the current page. I thought this was pretty standard menu behaviour, but it took me a couple of hours to figure out.
Here’s the solution:
In the design view, edit the properties of the menu by clicking on its gears icon, go to the Content Filter section and put the following query in the WHERE condition field:
NodeAliasPath LIKE ‘{&/{0}/%&}’ OR NOT NodeAliasPath LIKE ‘/%/%’
This gets all items under the current one {0}, or anything that’s not a root element. You’ll have to make sure the Maximum nesting level is set appropriately, but that’s it.
Hopefully someone else with the same problem will stumble across this and save themselves an hour or two.
Hi Damian,
Interesting solution, thank you for posting this. However, it is not that common to use this behavior of the menu (display all child documents of all subdocuments at the same time), because the menu can get crowded and you won’t save much space in the menu just by eliminating single level of it. Also, such where condition is very expensive for the SQL server to evaluate.
I would also recommend to change OR NOT NodeAliasPath LIKE ‘/%/%’ to OR NodeLevel <= 1 (or appropriate level) which would be much faster if you really need this behavior.
In most cases, it is better to just use the settings "Display only selected path", which is much more efficient and displays only child documents of the current document and the path to it which filters the menu to the items of current context and nothing around it.
Hi Martin,
Thanks for the comment – I’m just starting on Kentico, so your reply will be very helpful!
I will have a look at the “Display only selected path” setting – it looks like it’s actually closer to what I want to do. I’ll always want the root items to appear as well though, so that could be a problem. Hopefully there’s an easy way to combine the two. The node level suggestion is a very good one. At the very least, I’ll switch that part of the query.
I know what you’re saying about the number of menu items being quite large, but there are not too many pages on the site I’m dealing with. I can see how it would be a problem with a larger site though. I guess that while it’s fine with the site I’m working with, it’s not a very reusable solution.
I will definitely try your suggestions out, and thanks for the reply!
Damian
Hi,
This sounds like exactly I need to do.
Could you please direct me towards the ‘Display only selected path’ setting?
I can’t seem to find it anywhere in the settings.
Kind regards
Micheal.
Hi Michael,
Unfortunately I’m not near a machine that I can test with, but from memory it’s a checkbox in the settings of the actual menu control itself. If you can’t find it, I’ll have a look next time I’m able to.
Thanks,
Damian
Hi Damian,
Not sure what the option is that Martin speaks about, but you may find the following page useful:
http://devnet.kentico.com/docs/devguide/index.html?appendix_b___path_expressions.htm
It’s more specific to v5.0 onwards, but also works with (at least) v4.1.
I found that you can set the path to ./% for just the current path though this won’t help your situation, I think you’ve done the best thing if you always need to display level 1 links, but then only level 2 (onwards I’d imagine) for the current path.
Hope this is a useful reference for future,
Regards,
Kurt Farrar
MyDigitalMedia
Kentico Certified Partner