Rendering parts of a content type manually?

Topics: Customizing Orchard, Writing themes
May 4, 2011 at 9:23 AM

Hi,

I have a content type, product, defined in my module migration as follows;

ContentDefinitionManager.AlterTypeDefinition("Product",
	cfg => cfg
	.("BodyPart")
	.WithPart("CommonPart")
	.WithPart("RoutePart")
	.WithPart("ContainablePart")
	.WithPart("ReviewsPart")
	.WithPart("ImageGalleryPart")
	.Creatable());

I then have a list container for these products and I wanted to override how these are summarised and so in my theme, I created Content-Product.Summary.cshtml as follows;

@using Orchard.Core.Routable.Models
@using Orchard.ContentManagement.ViewModels
@using Orchard.ContentManagement
@using Orchard.Core.Common.Models
@using ProductTypes.Models

@{
	ContentItem item = Model.ContentItem;
	SynopsisPart sPart = item.As<SynopsisPart>();		
	RoutePart rpItem = item.As<RoutePart>();
	CommonPart cPart = item.As<CommonPart>();
		
	var linkUrl = Url.ItemDisplayUrl(item);
	var synopsisText = (sPart.Synopsis.ToString()).Replace("\n", "</p><p>");
	var thumbnailUrl = sPart.ThumbnailUrl == null ? "" : sPart.ThumbnailUrl.ToString();
	
}

<h4><a href="@linkUrl">@rpItem.Title</a></h4>
@* Here I want the review rating stars *@
<div>
	@if (!String.IsNullOrEmpty(thumbnailUrl))
	{
		<img src="@thumbnailUrl" align="left" width="150" height="150"/>
	}
	<p>@Html.Raw(synopsisText)</p>
</div>

My problem is, I'm manually overriding the rendering of the content type here, rather than letting the parts that make up the type render themselves, but I want the default rendering of the ReviewsPart (to display the nice rating stars). How do I go about rendering that specific content part manually in my template?

I guess another obvious question here is - am I going about this the right way?

Regards

Tony

Coordinator
May 4, 2011 at 5:25 PM

You should learn about part templates and placement. Here are good places to start:

http://orchardproject.net/docs/Understanding-placement-info.ashx

http://orchardproject.net/docs/Accessing-and-rendering-shapes.ashx

May 5, 2011 at 9:56 AM

Thanks, that was very useful, I'm refactoring now to override the way some parts render and suppressing the ones I don't need with placement.info.