Shape alternates for content shown in projection widget

Topics: Customizing Orchard, Writing modules
Jan 12, 2015 at 2:30 AM
Often times I want to render a shape differently in a projection widget to how I would render it if it showed up in e.g. search results. However, there isn't a built-in alternate to determine whether a shape is contained within a widget/projection.

Also, I don't think shapes have any knowledge of their parent container (list, widget, whatever), so I can't think of any way to make a custom shape table provider which includes info about the parent container in the alternate.

Does anyone have any recommendations for a re-usable way of doing alternates for displaying differently depending on containment within a widget type/name?
Jan 12, 2015 at 7:11 AM
Edited Jan 12, 2015 at 7:16 AM
For a projection widget there is a simple way. In your projection querie, add a layout and specify a custom DisplayType, e.g "YourDisplayType", and select this layout in your widget settings. Then, you will be able to override your items (assuming they are Pages) by using this file in your theme
Views/Content-Page.YourDisplayType.cshtml
Note that you have to add, in the theme placement.info file, the parts you want to display in your custom display type
<Match DisplayType="YourDisplayType">
    <Place Parts_Title="Header:5"/>
    <Place Parts_Tags_ShowTags="Header:after.7"/>
</Match>
For other cases, I think there are some ways. I don't remenber exactly, but I can retrieve it case by case if you need it in a specific scenario. Maybe by overriding the parent shape and by adding some dynamic data in the child models...


Regards
Jan 12, 2015 at 9:31 PM
Thanks! Funnily enough, I've used that before... I just completely forgot it existed haha. Such is life with Orchard!