How can I render a Part in a template?

Topics: Customizing Orchard, Writing themes
Dec 25, 2014 at 4:28 AM
Edited Dec 25, 2014 at 4:31 AM
There are many parts in a page. For examples, TitlePart, CommentsPart, TagsPart.
My question is, how can I render a part?

My content type is News, I can show the TitlePart use:
<p>@Model.ContentItem.News.TitlePart.Title</p>
But how can I render the CommentsPart / TagsPart?
I think i can use:
<p>@Display(BuildDisplay(Model.ContentItem.News.TitlePart))</p>
but it cause a stack overflow error.

anyhelp is appreciate.
Dec 25, 2014 at 6:56 AM
you can builddisplay for content item, but not content part.
but there're workarounds , such as :
  • create an alternate for the content item that display only your part.
  • create a custom display type and configure the placement.info to display only your part
  • display the same shape as the one used in your driver.
thx
juna
Coordinator
Dec 27, 2014 at 10:30 PM
Developer
Dec 27, 2014 at 10:51 PM
Also, the Orchard.Layouts module provides a service for just that purpose: rendering individual parts and fields:
  • IContentPartDisplay
  • IContentFieldDisplay