This project is read-only.

Placements/Alternate based on Zone

Topics: Customizing Orchard, Writing themes
Jul 5, 2015 at 5:16 AM
I am building a theme for my website. I have a projection of ContentItems in AsideSecond (DisplayType = Summary) and also a page in Content which shows a summary list of the same ContentItem type.

I have made a layout shape for the query that the projection uses, so it is functionally what I need.

What I wanted to know is if it was possible to use Alternate naming or the Placement file to override the template based on which zone I am rendering.

If I use the alternate Parts.Title.Summary-<ContentType> it is rendered on both zones. I was hoping for something like Parts.Title.Summay-<Zone>-<ContentType> or something similar to exist.
Jul 8, 2015 at 12:19 AM
Edited Jul 8, 2015 at 12:54 AM
I'm surprised no give me an answer to this. It seems like a straightforward yes or no question.

I'll try to explain more clearly. I have a ContentType called Animal with say, a TitlePart. On one Page (in the Content zone) I display a list of summaries (DisplayType = Summary) of Animals. I would like to see the title of each Animal in this list.

I also want to render a brief list of the latest Animals in the AsideSecond zone. I have written a Query and created a Projection Widget for this. Here, however I want to suppress the title. The widget also renders a list of summaries (DisplayType = Summary).

If I do the following in my file, it suppresses the title in both zones:
<Match ContentType="Animal">
    <Match DisplayType="Summary">
        <Place Parts_Title_Summary="-"/>
As I said I created my own layout shape for the Projection Widget, and it works. But, I was still wondering if there was a way to suppress certain parts based on the zone they are contained in. Is this possible using alternate naming and the placement file, or will I always have to write my own layout shape? My web designer is confident enough to use the placements and alternates with the Shape Tracing feature, but she isn't able to write whole new template files from scratch.
Jul 8, 2015 at 10:31 AM
The challenge is that you can't easily know what zone your part shapes are being rendered in. If you wanted to add alternates to the Widget shape then that would be easy, since widgets know to which zone they belong.

So the short answer is: no, not out of box.
However, you could implement an IShapeTableProvider and describe the Widget shape. This shape will contain a reference to the ContentItem (which will have a WidgetPart attached through which you can access the zone name it belongs to) and child shapes (including shapes like Parts_Title_Summary), so you could walk this shape tree and add alternates to each based on the zone name.

Not pretty, but it could work.
Jul 8, 2015 at 11:25 AM
Cheers, mate. I assumed it would be something along those lines. As I said I just wrote my own template for the query and all is good in my projection widget.

I thought there might be a way to use the placements file (<Match ZoneType="AsideSecond"> or similar) that could be used. I think that would be a nifty feature.

Maybe if I get this new site up and running I will poke around in the Orchard code and see how it all pulls together. It's really an impressive piece of software.
Jul 9, 2015 at 5:38 AM
An alternative I usually use is to have two Raw layouts for the query used in the projection and in the projection widget.
  • The Summary layout: With default values you get when you create a layout for a query.
  • The SimpleSummary layout: Like previous one but I change the displaytype of the layout to 'SimpleSummary'
For the Projection you continue using same query with Summary layout.
For the Widget Projection you use same query but with SinpleSummary layout.
Then in the placement you can use DisplayType to remove title for SimpleSummary renders and to put title for Summary reders.
Jul 9, 2015 at 6:05 AM
I'll take a look when I get home from work. I think I tried that, but due to the structure of the NGM.Forum models I don't think I can bind to all the properties I want to in a raw layout.

Good tip though for future reference for my own module development. Thank you.