我有一个小部件的备用视图。在那个视图中,我使用这样的代码来抑制包装:
Model.Metadata.Wrappers.Clear();
这有效,但我只想压制Widget.Wrapper。现在它还抑制了Widget.ControlWrapper,当我启用了Widget Control Wrapper模块时,它会阻止显示编辑按钮。
有没有办法在保留Widget.ControlWrapper时只清除Widget.Wrapper?
答案 0 :(得分:2)
如果有人遇到类似的问题,我可以在我的主题中的Widget-Sidebar.cshtml文件中压制Widget.Wrapper:
@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)
我首先使用“形状跟踪”工具为“侧边栏”列中的小部件创建了一个替代方案(基本上是<div id="sidebar">
我的布局中为@Zone(Model.Sidebar)
。)
我将上面的代码放在我使用Shape Tracing创建的Widget-Sidebar.cshtml替代中。
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");
似乎是正确的方法(即,Shape Tracing仍显示Widget),但它似乎删除了所有其他包装器,因此您必须添加新的包装器以及Widget.ControlWrapper.cshtml(写为“ Widget_ControlWrapper“在上面的代码中。”
HTH。
答案 1 :(得分:0)
我能够像这样添加Widget.ControlWrapper:
Model.Metadata.Wrappers.Add("Widget_ControlWrapper");
这似乎就像我想要的那样工作。