How to add an id attribute to the main menu?

Topics: Writing themes
Apr 11, 2013 at 5:01 PM
Hi Guys,

I am trying to create an Orchard theme and want to customize the main menu. All I need to do is add an id attribute to the main ul element. I can understand that I need to copy the Menu.cshtml view in my theme and in the Razor view have this line of code:
Model.Attributes.Add("id", "someId")
By the way I had to dig in the Orchard code to find this out. It is amazing how little documentation there is to Orchard.

Anyways, I was wondering is there a way to do this without having to override the view?
I don't want to clutter my theme with additional views just to add an attribute to the part (model, whatever it is called in Orchard). I looked at a theme, which had a LayoutFilter.cs, which was adding some weird routing for the layout, but I could not find any information on how action filters can be used in Orchard. I added my own LayoutFilter.cs to the theme so that I can try and customize the Menu Model but some weird stuff happened when I was debugging it, the debugger was picking the LayoutFilter from the other theme.
I hope this is not too much to ask, but I am trying to learn as many things as possible about Orchard by just achieving this simple task of adding an attribute to the main menu ul element.

Many thanks
Apr 12, 2013 at 12:33 AM
I'm pretty sure you could do that from a shape table provider.

The documentation is open-source and driven by the community. If you want to help, please head to GitHub :)
Apr 12, 2013 at 3:22 PM

Thanks for this. Yes the IShapeTableProvider seems like the best way to achieve this.
I think you can also do it with a filter somehow? If I find more I find more I will share it.
Regarding the IShapeTableProvider, this short article is really useful: