Design and CSS styles
Version 7.x > Design and CSS styles > Programatically add class to menu item View modes: 
User avatar
Member
Member
joelbower-gmail - 3/18/2013 5:35:17 PM
   
Programatically add class to menu item
I was wondering if it is possible to add classes to li items withing a CSS List menu web part.

I'm trying to add a class stating whether the item has children or not, but from the looks of things the only way to do so is to go into each page and add a class manually. I want the process automated, so that if there are children underneath it a class (e.g. 'has-children') is added to the li

Any ideas?

User avatar
Kentico MVP
Kentico MVP
Brenden Kehren - 3/18/2013 10:27:08 PM
   
RE:Programatically add class to menu item
Check out the hierarchical viewer web part. You can create transformations for different levels. Works awesome in place of nested repeaters. Any particular reason you don't want to use the cmslistmenu? Seems like it would serve the purpose your looking for.

User avatar
Kentico Support
Kentico Support
kentico_radekm - 3/19/2013 4:04:35 AM
   
RE:Programatically add class to menu item
Hello.

As FroggEye suggested, you could consider Hierarchical transformations and define classes in the transformation. More info can be found at http://devnet.kentico.com/docs/devguide/index.html?hierarchical_transformations.htm

The CSS List menu web part can generate class names automatically (if you enable this in the configuration dialog). However, if you want to change their names, you would need to override RenderedHTML property and replace default class names by custom class names.

Best Regards,
Radek Macalik