Accessing fields of a content type from an attached part

Topics: Writing modules
Jun 29, 2012 at 1:37 PM
Edited Jun 29, 2012 at 7:14 PM

I'm expanding on the static map tutorial a bit (, where I have two fields in my static map part that I would like to use to reference fields in the content type they are attached to.

I.e., I have a custom content type called location, and it has two fields, Address1 and Address2.

The content part I'm writing has two fields as well: Address1Field, Address2Field. So the user would enter 'Address1' and 'Address2' respectively, and then somehow I pull data from those two fields in my custom content type...and this is where I'm stuck. Does what I'm trying to do make sense?

Jun 30, 2012 at 7:06 AM

By field do you mean property of the part, or field in the Orchard sense? I'm a little confused about your scenario. Can you explain a little more?

Jul 2, 2012 at 7:18 PM

Sure thing. Here's the problem I'm trying to solve:

The map tutorial that I linked talks about implementing a static map part that has two fields: Longitude and Latitude. You attach this part to your existing content items, and enter the two values in, which in turn render a static map. Since this isn't convenient for non-technical end-users, what I want to do is use two address fields, passing them to the map instead and letting a 3rd party geocode them. I don't want to have the user enter them, though, like the original part had them enter latitude and longitude - instead, I want to dynamically pull them from whatever content they're attached to.

So I make a new content type (Location) with 2 fields - Address1 and Address2. These are where I'm storing the actual data that I will eventually geocode (i.e. Street Address, City, State, Zip). I then attach my static map part to this piece of content. Now, when I go to edit a piece of Location content, I've got Address1Field and Address2Field. In these, I would type in 'Address1' and 'Address2' respectively. Then, when my static map part renders, I would like to grab the text from those other two fields in my Location content part, and do something with it in my static map part.

Assuming that made sense, my problem comes in how I would grab the text from the actual field that 'Address1Field' is pointing at. I'm just not sure how, programatically, I can inspect the content to which my part is attached and find its elements - or if I even can.

Jul 4, 2012 at 3:23 AM

I'm sorry, but that doesn't make much sense to me: I don't see any reason why Address1 and Address2 would not be on the geolocation part. That's where they belong. If you still want your part to rely on external data that may or may not be there, well, you can cast the content item to dynamic and then acces any field or part: contentItem.NameOfTheType.Address1 for example.