Template for ContentType

Feb 13, 2011 at 12:22 PM

I have a new ContentType; Book . It has Image (ImageField) and Link (Hyperlink Field)

I want to customise how it is rendered. 
So as per this discussion http://orchard.codeplex.com/discussions/237723?ProjectName=orchard I have created a
Content-Book.Summary.cshtml which works ( i can see static text I add).

I have also read the shape documentation but still can't work out how to access the records data

My question (finally :) )

How do I access the Record data? i.e. @Model.Link
Once I have that data, how do I render a field as it should be? i.e. I just want to wrap the image and the Title in the Link, I don't want to have to write html to render the img etc, I just want to delegate that back to the image field template, the url to the url field etc.




Feb 14, 2011 at 9:36 PM

Today rendering fields is way more complicated than it should be, and we're addressing that in Orchard 1.1. In the meantime, you can do this:

@(((ImageField)((ContentItem)Model.ContentItem).Parts.First(p => p.PartDefinition.Name == "Book").Fields.First(f => f.Name == "Image")).Value)

To access record properties, you should be able to just do @(((MyRecordType)((ContentItem)Model.ContentItem).Record).Link)

Feb 15, 2011 at 8:30 PM
Edited Feb 15, 2011 at 8:32 PM

Thanks, using the the example with the appropriate usings, i just get the object's tostring() Contrib.ImageField.Fields.ImageField

It looks like there is still more required to render the ImageField, a method call?

Edit: Value is not part of the object, so I am just returning the ImageField.I can't see a different property rather than Value that looks promising.




Feb 15, 2011 at 9:22 PM

FileName? ImageField seems to have FileName, AlternateText, Width and Height. Value was for the text field.

Feb 16, 2011 at 8:43 AM

Sorry, you are right. But I was wondering if there was a way to re-use the ImageField Template to render the IMageField in my template rather than re-writing the HTML from the ImageField Template.




var imageField = ((ImageField)((ContentItem)Model.ContentItem).Parts.First(p => p.PartDefinition.Name == "Book").Fields.First(f => f.Name == "Image"))








Feb 28, 2011 at 1:29 PM

It seems like AdamMills want the same thing i want, to render the shape belonging to a field directly from within another view.

Feb 28, 2011 at 6:54 PM

Can you explain exactly what it is you are trying to do (that you cannot do with placement)?

The field is not a shape. The shape is created by the field's driver, and can then be positioned in a content zone using placement.info. You could also create your own shape from the field's data, essentially replicating what the driver is doing, and call display on it, but I don't really see the point of that.