开发者

Can Wrappers in Orchard CMS have alternates?

开发者 https://www.devze.com 2023-03-27 22:58 出处:网络
I\'m curious if I can somehow make the Widget.Wrapper shape (or other wrappers) alternateable, because it contains most of the widgets\' HTML code. I don\'t like rich IF statements in cshtml files, th

I'm curious if I can somehow make the Widget.Wrapper shape (or other wrappers) alternateable, because it contains most of the widgets' HTML code. I don't like rich IF statements in cshtml files, therefore I'd rather use a clear solution using the alternates mechanism - being able to create alternates like these:

Widget.Wrapper-[ZoneName].cshtml
Widget.Wrapper-[WidgetId].cshtml
Widget.Wrapper-url-[UrlAlternate开发者_运维技巧].cshtml

etc.

Is that possible? Or are the wrappers a special case - and in that case why?

Thanks


Yes, it's possible. You can do it with IShapeTableProvider. Catch the shape that your widget it rendering, decide which wrapper you want, and then add a new wrapper.

builder.Describe("YourShapeHere")
    .OnDisplaying(displaying=>{
        displaying.ShapeMetadata.Wrappers.Add("Widget_Wrapper-" + displaying.Shape.Id);
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消