Mode.ContentItem.ContainerPart (getting at list of items in Container?)

Topics: Customizing Orchard, Writing themes
Jan 5, 2012 at 6:02 AM
Edited Jan 5, 2012 at 6:20 AM

I have a custom object and it's a container using the container part.  I also have another Custom Type that is containable and has 4-5 unique text fields.

 

The default View obviously renders the custom object + a list of my sub types but when I try to customize this view, I'm getting stuck on how to interate through the list of items.

 

So Far I have Model.ContentItem.ContainerPart...... but not sure within there how I get to and access the list of parts within it.  I'm using shape tracing but I'm obviously missing something here.

 

Any thoughts?

 

EDIT: to clarify, I'm trying to in the cshtml file get access to the list of key/value pairs so that the contenttype that contains the list of items can render things based on it.

Jan 5, 2012 at 7:18 PM
Edited Jan 5, 2012 at 7:20 PM

I still havn't figured this one out yet. I can get to the container part but I'm not able to see the MapLocations that are within the Container from the View of the MySite. Any idas?

Here are the types:
     <MySite ContentTypeSettings.Creatable="True" ContentTypeSettings.Draftable="True" DisplayName="MySiteLanding">
        <CommonPart OwnerEditorSettings.ShowOwnerEditor="True" DateEditorSettings.ShowDateEditor="False" />
        <BodyPart BodyTypePartSettings.Flavor="html" />
        <RoutePart />
        <TitlePart />
        <MySite />
        <ContainerPart ContainerTypePartSettings.PageSizeDefault="10" ContainerTypePartSettings.PaginatedDefault="True" />
        <AdminMenuPart AdminMenuPartTypeSettings.DefaultPosition="2" />
      </MySite>
      <MapLocations ContentTypeSettings.Creatable="True" ContentTypeSettings.Draftable="True" DisplayName="MapLocations">
        <CommonPart OwnerEditorSettings.ShowOwnerEditor="True" DateEditorSettings.ShowDateEditor="False" />
        <ContainablePart />
        <MapLocations />
        <IdentityPart />
        <TitlePart />
      </MapLocations>
And here are the parts:
      <MySite ContentPartSettings.Attachable="True">
        <MapImage.ImageField ChoiceListFieldSettings.Options="" ChoiceListFieldSettings.ListMode="dropdown" FileFieldSettings.Required="False" FileFieldSettings.OpenAction="_blank" HtmlFieldSettings.FlavorDefault="html" ImageFieldSettings.MaxHeight="0" ImageFieldSettings.MaxWidth="0" ImageFieldSettings.Required="False" ImageFieldSettings.AlternateText="False" ImageFieldSettings.ResizeAction="Validate" />
      </MySite>
      <MapLocations ContentPartSettings.Attachable="True">
        <XLocation.TextField ChoiceListFieldSettings.Options="" ChoiceListFieldSettings.ListMode="dropdown" FileFieldSettings.Required="False" FileFieldSettings.OpenAction="_blank" HtmlFieldSettings.FlavorDefault="html" ImageFieldSettings.MaxHeight="0" ImageFieldSettings.MaxWidth="0" ImageFieldSettings.Required="False" ImageFieldSettings.AlternateText="False" ImageFieldSettings.ResizeAction="Validate" />
        <YLocation.TextField ChoiceListFieldSettings.Options="" ChoiceListFieldSettings.ListMode="dropdown" FileFieldSettings.Required="False" FileFieldSettings.OpenAction="_blank" HtmlFieldSettings.FlavorDefault="html" ImageFieldSettings.MaxHeight="0" ImageFieldSettings.MaxWidth="0" ImageFieldSettings.Required="False" ImageFieldSettings.AlternateText="False" ImageFieldSettings.ResizeAction="Validate" />
        <Description.TextField ChoiceListFieldSettings.Options="" ChoiceListFieldSettings.ListMode="dropdown" FileFieldSettings.Required="False" FileFieldSettings.OpenAction="_blank" HtmlFieldSettings.FlavorDefault="html" ImageFieldSettings.MaxHeight="0" ImageFieldSettings.MaxWidth="0" ImageFieldSettings.Required="False" ImageFieldSettings.AlternateText="False" ImageFieldSettings.ResizeAction="Validate" />
        <URL.TextField ChoiceListFieldSettings.Options="" ChoiceListFieldSettings.ListMode="dropdown" FileFieldSettings.Required="False" FileFieldSettings.OpenAction="_blank" HtmlFieldSettings.FlavorDefault="html" ImageFieldSettings.MaxHeight="0" ImageFieldSettings.MaxWidth="0" ImageFieldSettings.Required="False" ImageFieldSettings.AlternateText="False" ImageFieldSettings.ResizeAction="Validate" />
      </MapLocations>
Coordinator
Jan 5, 2012 at 8:21 PM

Why do you want the list of parts? Why don't you ask content manager to generate display shapes for you?

Jan 5, 2012 at 10:02 PM

Sorr not sure I follow. Are you suggesting code that tells the container the render the shapes? How exactly? I'm just starting to play with razor views

--------
John
Sent from a mobile phone

On Jan 5, 2012 2:21 PM, "bertrandleroy" <notifications@codeplex.com> wrote:

From: bertrandleroy

Why do you want the list of parts? Why don't you ask content manager to generate display shapes for you?

Read the full discussion online.

To add a post to this discussion, reply to this email (orchard@discussions.codeplex.com)

To start a new discussion for this project, email orchard@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com

Coordinator
Jan 5, 2012 at 10:51 PM

Parts and shapes are different things. Shapes are typically created from part data in a driver, and then templates render the data from the shapes.

Getting the parts of the container would only get you so far, what you need is for the drivers to run on your parts so that you can get shapes to render. Makes sense?

What I'm suggesting is that you ask the content manager to call build display on the container item, so you get shapes that can then be rendered. The clean way to do this would be to implement a part and do the work from that part's driver.

All that is if you want full rendering of the container. Then again I'm not sure what it is you are trying to do. If you are just trying to render a few properties from the container, you probably need all of that and could just do @Model.ContainerPart.etc from your view.

Jan 6, 2012 at 1:31 AM

Perhaps what I'm trying to do isn't appropriate.  I want to have a content type that contains a map image.  Then I want it to contain a list of items that have X,Y pixel locations, name, url etc.  The View will display the map, place "dots" on the map where the X,Y location is at for each of the items in the list of locations.

 

The plan was to create two custom types MySite and MapLocations(see my post with the XML)

The MySite would contain a list of the MapLocations.

MapLocations was overridden in the theme to write binding data elements

MySite was over ridden with the purpose of displaying the map then running through the MapLocations in order to place dots in the right area.

 

make sense?  better approach to take?

 

Seriously.... thanks for your assistance and walking me though this!

Jan 6, 2012 at 2:01 AM
bertrandleroy wrote:

 If you are just trying to render a few properties from the container, you probably need all of that and could just do @Model.ContainerPart.etc from your view.

That is exactly what I'm trying to do but I'm struggling with getting to the list of items in the container part.

 

Model.ContentItem.ContainerPart is confirmed to be a List<MapLocations> but for the life of me, I can't figure out how to loop through and access each item in the list (or a single item for that matter).  Shape Tracing I'm sure should have it but I'm apparently missing it.

If I create a list called "testlist" and associate two MapLocations to it, in the Shape Tracer, I can clearly see in the list.

 

The key is that the default view is just "@Display(Model.Content)" which will let each part render itself.  What I want is to use the meta data inside the child parts to ultimately create a bunch of dots on the map.

 


Coordinator
Jan 6, 2012 at 2:15 AM

Well, yes, that's a list of locations, that's no simple property. You need to render that container fully, maybe with a custom display type. I would definitely go for a custom part here. Writing the custom template is the easy part.

This being said, now that I know what you are trying to do, maybe you should take a look at this: http://gallery.orchardproject.net/List/Modules/Orchard.Module.NogginBox.BingMapList

And well, if you do a search on "map" on the gallery you'll find a few interesting things that might help you.

Jan 6, 2012 at 2:44 AM

This one needs to be "offline" but thanks for the suggestion, I should be able to examine that code and make an offline version of that very thing.  Thanks.