Sub menus in new Navigation

Topics: Writing modules, Writing themes
Aug 17, 2012 at 7:38 PM

I've been a HUGE fan of Advanced Menu, but I'm really liking the new Navigation features is 1.5.1. I'm doing a bit of customization in my theme and have a question.

Currently, I'm modifying MenuItem.cshtml. I'm adding a class to create a dropdown if the 1st level menu item has any children

if(items.Any()) {

This works great and any items under level 1 are populated in a dropdown.

I'd like to add a 3rd level so that my hierarchy looks like this

Level 1
          Level 2-1

what I need to be able to do to achieve the correct styling, is if I'm at any level greater than 1 and there is an item in a level below it, I need to change the class I'm adding from "dropdown" to "dropdown-submenu".

Is this a possibility? Is there anything in the Model that can help me identify what level I'm at when rendering the  item?

Thanks so much for the help!

Aug 17, 2012 at 8:21 PM

Making a little bit of progress...I wrote this

    if(items.Any()) {
        foreach(var item in items) {
            if (Model.Text.ToString() == "Link 1") {
            else {

which is obviously just a hard-coded check on the link text. But the behavior is exactly what I want.

Can someone maybe tell me where I can find the other properties of Model in this case? Or perhaps using Model, can I determine if there are children?

Aug 20, 2012 at 7:09 AM

Why don't you just target your style to something like .dropdown .dropdown?

Aug 20, 2012 at 6:30 PM

Thanks...I never actually thought of doing it that way. I'm using Bootstrap, so I just had to duplicate the styles for "dropdown-submenu" and replace them with ".dropdown .dropdown". Works great, and I suppose I can probably do additional levels by defining styles for ",dropdown .dropdown .dropdown" for 3 levels deep.

Once again you've made my life much easier =) Thanks!