Rendering parts of a content type manually?

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


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

	cfg => cfg

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 *@
	@if (!String.IsNullOrEmpty(thumbnailUrl))
		<img src="@thumbnailUrl" align="left" width="150" height="150"/>

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?



May 4, 2011 at 5:25 PM

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

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