Accessing fields on a ContentItem

Topics: Writing modules
Aug 24, 2011 at 6:56 PM

I've got a ContentType "Event" that has a "location" field on it.  I used the work context to query for a list of Events on a widget.  When I display these in my display view, I need to be able to access the value of that field (and other fields) and print the information out.

I know I've done this before, but I can't figure it out.  I've been looking through ShapeTracing and the debugger but cannot seem to find how to access the fields on my content item.


var eventQuery = _cms.Query(VersionOptions.Published, "Event").List();
return ContentShape("Parts_Events"
                () => shapeHelper.Parts_Events(
                                         Events: eventQuery,
                                         Title: part.ContentItem.As<WidgetPart>().Title));



@foreach(var eventItem in Model.Events)
    <div>Event will be held at @eventItem.Fields.Location</div>
Aug 24, 2011 at 7:05 PM

Should be something like eventItem.Events.Location.SomePropertyOfTheFieldMayBeValue.

Aug 24, 2011 at 7:07 PM

Hmmm, That looks right. are you sure the values are being populated? Also is the Parts_Events in the file?

Aug 24, 2011 at 7:09 PM

I just looked, bertrand was right, it was eventItem.Event.Location.Value.  The "Event" part that I bolded was the part I was missing...I swear I remember seeing a fields property, but this looks nicer.  So it must create a dynamic with the same name as the ContentType...I think Bertrand might have told me that once before.