Rendering of field in view

Topics: General
Aug 27, 2015 at 4:54 PM
Edited Aug 27, 2015 at 4:56 PM

We currently have a view that is rendering a field from a content part as follows:
This appears to circumvent the driver for the field, in this case, the TextFieldDriver.

Is there a way to display the field as a shape, so it goes through the driver?

Aug 28, 2015 at 10:44 AM
By default, field drivers will execute to build the shape for the field. If you want precise control over where this shape is rendered in the content shape template, just render a zone there and update your file to place the shape in that zone. For example, given the following:
  • Content type: Alpha
  • Content Field: AlphaField
  • Local zone: AlphaZone
Then your content view could look like this:

And your like this:
<Place Fields__AlphaField="AlphaZone:0" />
This gives you control over where the field is rendered in your content template and have the field driver still execute.
Now this placement won't work outside the context of a content shape template, so if you ever needed to generate the shape(s) of some content field from an arbitrary location in code, you could leverage the IContentFieldDisplay service that lives in Orchard.Layouts. That one lets you render individual fields and gives back a root shape, which you can render anywhere.
Marked as answer by stuart2424 on 8/28/2015 at 6:45 AM
Aug 28, 2015 at 11:34 AM
Ah, thank you. I didn't realise that you could define local zones in Orchard. That's very useful.

I have it working now, thank you!