share ideas two different menu styles (main menu and sidebar menu)

Topics: Customizing Orchard, General
Aug 7, 2013 at 7:27 PM
hi,
i have done style two different menu for my project. I thought this may help someone.

I first added a bool field on the content type menu, I named Issidebar (with default value is false)

continue, open the menu that you want, change the value of Issidebar.

then in Menu.cshtml (you can see it in core/Shapes/view), I use it to identify menu in sidebar and add class to style it.

this is code:
@using Orchard.Utility.Extensions
@{
    // Model is Model.Menu from the layout (Layout.Menu)
    var tag = Tag(Model, "ul");
    
    var items = (IList<dynamic>)Enumerable.Cast<dynamic>(Model.Items);

    bool? Issidebar= Model.ContentItem.Menu.Issidebar.Value;

    if(Issidebar.HasValue){
       tag.AddCssClass("sf-menu sf-vertical");
    }
    else {
       tag.AddCssClass("sf-menu");
    }

   
    if (items.Any()) {
        items[0].Classes.Add("first");
        items[items.Count - 1].Classes.Add("last");
        
    }    
}
<nav>
    @tag.StartElement
        @* see MenuItem shape template *@
        @DisplayChildren(Model)
    @tag.EndElement
</nav>
done. happy day

P/S : Sorry about my english, it is not my main language, but I hope you can understand. :):)