Suppressing Widget.Wrapper without suppressing Widget.ControlWrapper

爱⌒轻易说出口 提交于 2019-12-12 01:57:19

问题


I have an alternate view for a widget. In that view I'm suppressing the wrapper using code like this:

Model.Metadata.Wrappers.Clear();

This works, but I'd like to only suppress the Widget.Wrapper. Right now it is also suppressing the Widget.ControlWrapper which prevents the edit buttons from displaying when I have the Widget Control Wrapper module enabled.

Is there any way to clear only the Widget.Wrapper while keeping the Widget.ControlWrapper?


回答1:


In case anyone comes across this for a similar problem, I was able to suppress the Widget.Wrapper thusly in a Widget-Sidebar.cshtml file in my theme:

@using Orchard.DisplayManagement.Descriptors;
@using Orchard.Environment.Extensions;
@{
    Model.Metadata.Wrappers.Remove("Widget_Wrapper");
    Model.Metadata.Wrappers.Add("Widget_SideBarWrapper");
    Model.Metadata.Wrappers.Add("Widget_ControlWrapper");
}
@Display(Model.Content)

I started out by using the Shape Tracing tool to create an alternate for widgets I had in a "sidebar" column (basically a <div id="sidebar"> I have in my layout as @Zone(Model.Sidebar)).

I placed the code above in the Widget-Sidebar.cshtml alternate that I created using Shape Tracing.

Model.Metadata.Wrappers.Clear(); as used by the OP completely removes everything, to the point where in Shape Tracing it won't even show up as a widget. Adding my own alternate (Widget.SideBarWrapper.cshtml, which is added as "Widget_SideBarWrapper" above) would not fix this. I felt that was wrong even though the content displayed.

Model.Metadata.Wrappers.Remove("Widget_Wrapper");

seemed the right way to go (i.e., Shape Tracing still showed a Widget), but it appears to REMOVE all the other wrappers, so you then have to add your new wrapper along with Widget.ControlWrapper.cshtml (written as "Widget_ControlWrapper" in code above).

HTH.




回答2:


I was able to add back the Widget.ControlWrapper like this:

Model.Metadata.Wrappers.Add("Widget_ControlWrapper");

This seems to be working just like I wanted.



来源:https://stackoverflow.com/questions/13367453/suppressing-widget-wrapper-without-suppressing-widget-controlwrapper

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!