This project is read-only.

Custom type list customisation

Topics: Customizing Orchard, Writing themes
Nov 22, 2012 at 6:40 PM

I'm trying to get my head around how Orchard handles rendering of lists of custom types.

I've created a few custom types in the admin and linked them all together with some data.  

  • A Page will contain many Products
  • Each product will contain many ProductImages

If I leave it as the default rendering, the fields for Products are listed, but none of the ProductImages are shown for each Product.

I've installed the Designer module and poked around with alternate templates.  I just can't see how I can render the ProductImages for each product.  Is it likely I can do all my custom rendering via alternates, or do I need to dig deeper and look into Drivers etc?  The use cases for different customisations seem a little vague.

Also, on the topic of Drivers and custom code bits - if I were to create a custom Driver or other similar c#-style custom code, where do I put it?  Do I need to create a new module, or can I place it within my custom theme?

Nov 22, 2012 at 7:14 PM

Please provide more details about what you are trying to do, what you tried and how it failed.

Drivers should go in modules.

Nov 22, 2012 at 7:52 PM

This is my current Content-Product.Summary.cshtml alternate file:

<article class="content-item @contentTypeClassName">

	@if (Model.ContentItem.Product.Brochure.Url != null) 
			<img src="@Url.Content("~/Themes/MyTheme/Content/Images/page_white_acrobat.png")" height="16" alt="View Brochure" />
			<a href="@Model.ContentItem.Product.Brochure.Url" target="_blank">View Product Brochure</a>

As you can see, a Product has Details and a Brochure that I'm custom rendering.  Each product also has a container of ProductImages which have been created and assigned to the Product.  My question is - how do I render the ProductImages?  I'm looking through the Shape Tracer and can see that for each listed Product, the Model.ContentItem.ContainerPart.ItemContentType is "ProductImage".  The items aren't rendered by default, and I don't know how to iterate over the collection of attached ProductImages and render them.  Can I do this in the above alternate (what model property would I look at), or is there a better way?

Let me know if this isn't clear.


Nov 22, 2012 at 8:00 PM

Still not clear, sorry. Not knowing how your custom parts are written, it's impossible to say. What does ProductImage look like?

Nov 22, 2012 at 8:08 PM

Along with the default bits of Display Name etc, a ProductImage has an Image field, a Title Part, and a Containable Part.  A Product has Brochure and Details fields, and Title, Container, and Containable Parts.  So a Product is a Container for a ProductImage.

Nov 22, 2012 at 8:13 PM

I'm beginning to see what you mean. I think you should have a driver that calls BuildDisplay on content manager for those child content items and sticks the resulting shapes on the parent item's shape so that they can be picked up by the template and rendered using Display on them.

Nov 22, 2012 at 8:40 PM

Ok, thanks.  Let me now go figure out exactly what you mean by that, and how to do it!  I may be back...