From a content part can I find out which zone the content part / content type is going to be rendered in?

Topics: Writing modules
Oct 13, 2011 at 10:49 AM

Is it possible to find out which zone a content part will be rendered in from the content part driver?

I have added my own custom content part RelatedBlogPosts to BlogPost.

I have BlogPosts being rendered in various widgets in many different zones, but I only wish to render the RelatedBlogPosts content part for a BlogPost which is rendered in the Content zone.

At the moment the RelatedBlogPosts content part is being rendered with every BlogPost in every zone.

Any ideas?

Oct 13, 2011 at 12:17 PM

The trick is to use a different DisplayType depending on which zone you're rendering in. Then you can customise placement on a per-DisplayType basis, instead of hard-linking display behaviours to zone names. This gives you more flexibility overall.

Oct 13, 2011 at 1:19 PM

Thanks for the reply.

How do I use a different DisplayType depending on the zone? I can see the Display() function has a displayType parameter, but I dont know how to alter this parameter to identify that it is/isn't the Content zone.

Oct 13, 2011 at 2:03 PM

Well, it depends how you're rendering the blog posts. Are you using a widget?

Actually, in the normal use case, an item rendered in the Content zone will have DisplayType="Detail" whereas items rendered by widgets have DisplayType="Summary", so you could already use that to show the RelatedBlogPostsPart only in Detail.

Oct 13, 2011 at 2:23 PM

I am rendering the blog post in the normal case, not in a widget, and the displayType is indeed "Detail" and the rest of the blog posts on the page within widgets have the displayType "Summary".

Thank you very much!

Oct 13, 2011 at 3:36 PM

Great; so you should be able to use: <Match DisplayType="Summary"><Place Parts_RelatedBlogPosts="-"/></Match>

And you're done!