Ticket (Solved)

How can I override CoreShapes.cs in Menu.cshtml

Presuming it's possible at all.

CoreShapes.cs does this for the Menu shape:

            builder.Describe("Menu")
            .OnDisplaying(displaying => {
                var menu = displaying.Shape;
                string menuName = menu.MenuName;
                menu.Classes.Add("menu-" + menuName.HtmlClassify());
                menu.Classes.Add("menu");
                menu.Metadata.Alternates.Add("Menu__" + EncodeAlternateElement(menuName));
            });

This is problematic for some customized/purchased themes as it injects the following CSS into the <ul>: menu menu-main-menu. Essentially, it throws off jQuery functions that rely on CSS being in a set pattern. I don't know how to jQuery, so I thought I'd look at CoreShapes.cs first.

My theme has a .csproj file. Maybe I should be overriding that part of CoreShape.cs in my Theme?

Is there any way in the Menu.cshtml file (in my Theme's ~/Views folder) to disable this?

Is it Orchard injecting this CSS into my <ul> and causing my custom scripts to not show sub-menus?

Maybe I am altogether looking in the wrong place?

Apologies if I am not explaining this correctly. And thank you in advance for any answers/suggestions.

Re: How can I override CoreShapes.cs in Menu.cshtml

To me it seems that you should remove the classes that are generated by the CoreShapes methods.

If you override the Menu shape (Menu.cshtml), you can see that the Model (which is a shape of course) has two classes:

  • [0] = menu-main-menu
  • [1] = menu

Which are the classes you were referring to.

So regarding your questions:

>> Is there any way in the Menu.cshtml file (in my Theme's ~/Views folder) to disable this? They can simply be removed by adding e.g. this line of code inside your Theme View folder:

Menu.cshtml

Model.Classes.Clear();

Not sure if those CSS classes causing the problem, but at least you now know how to remove them and test your scripts.

Best, Daniel

Monday, June 6, 2016 1:47:38 PM bykonstrui

Re: How can I override CoreShapes.cs in Menu.cshtml

Thank you. I tried that but without the (), which was my mistake.

Monday, June 6, 2016 6:36:25 PM byremesq
  • remesq
  • Lv. 01 Rookie
  • Total EXP: 3

Post a reply

You need to be signed in to post a reply.

Sign In