This project is read-only.

Pass Main ContentItem Field Value To Custom Form Widget

Topics: General
Jun 10, 2012 at 10:04 PM

I'm building a real estate site... I'm using a custom form widget to display a "Request Showing" form on each "listing" details view. Each listing has a series of custom fields like MLS, Address, etc.

I'd like to include the MLS or URL from the listing in my email rule in order to identify which listing/house a user is requesting to see.

Is this currently possible with tokens? Or should I be looking at using some javascript to populate a field in the form and make it hidden it using an EditTemplate alternate?



Jun 10, 2012 at 10:15 PM

Sure, there are tokens for fields.

Jun 10, 2012 at 10:51 PM

Ok well here's what I'm trying to pull in my email: (ShowingRequest is the custom form content type, RealEstateListing is the content type where the form resides as a widget)

{Content.Fields.ShowingRequest.Name}<br />{Content.Fields.ShowingRequest.Phone}<br />{Content.Fields.ShowingRequest.Email}<br />{Content.Fields.ShowingRequest.ShowingDateTime}<br />{Content.Fields.RealEstateListing.MLS}

{Content.Fields.RealEstateListing.MLS} does not show up in my email.

Jun 11, 2012 at 1:03 AM

Compare the code of your field with the code of those other fields...

Jun 11, 2012 at 1:27 AM

I don't think you're picking up what I'm putting down...

ShowingRequest is a content item used as a form which is displayed as a widget beside a detail view of a RealEstateListing content item.

The form does not contain an MLS field. I want to grab field values from the RealEstateListing content item (which does have an MLS field) to include in my email rule. Obviously if the form has a field called MLS using {Content.Fields.ShowingRequest.MLS} will work, but my thinking behind this is simply, the data is there so why should I make the user input the value?

It seems like tokens can not be used to pulled data from other content items. That's why I asked if using javascript to inject/populate the value into a new "MLS" field in the form content item "ShowingRequest" would be an alternative to using ineffective tokens like {Content.Fields.RealEstateListing.MLS}.

hope that makes more sense now

Thanks for the help.

Jun 11, 2012 at 4:46 AM

Oh, I see. No, the widget doesn't know anything about what else is being displayed on the page. You'll have to come up with your own custom way of making them interact. One way to do this would be by having the driver for your field set some dynamic property on the layout object, and then making a custom token that surfaces that info. You could then use it in your custom form.

Jun 11, 2012 at 4:56 AM

;) Ok. Thanks for your help Bertrand!

Jun 11, 2012 at 6:03 AM

Just kinda thinking out loud.... I'm wondering if this is maybe something which could be more generalized as an additional field setting to make it function across all field types and custom forms.

Not sure where to start down that path nor how important this kind of feature really is in the bigger scheme of things, but maybe someone else does.

Jun 11, 2012 at 6:45 AM

This is what I ended up using for now. I just hide the field using css and now because the form actually has that field I can use the {Content.Fields.ShowingRequest.MLS} token. Not ideal, but this site pretty much requires javascript so I'm not too worried about non-JS accessibility for now.

@using (Script.Foot())

Jun 11, 2012 at 8:33 AM

No, you don't want that to be a generalized thing, I think.

Please don't do it through Javascript: there is no reason to do this and lots of reasons not to. As I told you, it's very easy to stick something on the Layout object and then get it back.

Jun 11, 2012 at 9:22 AM

"Easy" is a very subjective term... ; )

Jun 12, 2012 at 1:39 AM

Hello nxtjv,

I found a great module that you will likely want to look into called Contrib.ContentReference.  The URL for this module is here (I don't know if it is available in the gallery yet):

The git repository is here:

Read the wiki for more info:

You may still have questions (I did) so feel free to ask. Here is how I used it:

  • I needed a company hierarchy and I wanted the staff to show up on the location they were associated with
  • So, I created a content type called Staff and added a Content Reference Field (comes from this module) onto this Content Type
  • This field is driven off of a query so I made a query that selects all of the company locations
  • Then, when you are adding in your staff you can "link them" by selecting the company they belong to
  • Now, to get all of these staff to show up on the location page, I have a Projection Widget I added in the Content zone that uses a query to pull all Staff where the Staff Content Id is equal to the Location Content Id (done by using "Is equal to" operator and Value of "{Context.This.Id}"
    • This works because {Context.This.Id} is the Content.Id of the primary Content Type on the page

If you are reading that thinking it is complicated, it is just hard to type up. Once you use it once you will like the functionality of it and use it often.

  • As you can see in the Wiki, you can access more than just the Content Id from the page, technically you can access anything that the primary Content Type has access to as a token (such as the MLS number)

Hope you find this useful.

Jun 12, 2012 at 2:38 AM

No, really, it's super easy: Layout.Something = "yay!" and then to read it: var yay = Layout.Something.

@jao28: I think you are off-topic, I don't think this helps at all with this particular problem. Also, content references are built-in in the upcoming 1.5 version.

Jun 12, 2012 at 2:42 AM

Hi Bertrand,

I might be off (I just read this again and see he is just trying to pass it in an email rule - definitely off). However, I am glad to hear that this is built-in for the upcoming 1.5 version - it is a great feature.

Thanks for re-iterating the dynamic assignment available in Orchard, it is incredibly powerful.

Jun 12, 2012 at 3:21 AM
Edited Jun 12, 2012 at 3:21 AM

I appreciate the help guys! I'm just really lost when it comes to writing drivers, handlers or any of the business side. I'm really just spinning my wheels trying to make a module when 98% of it can be accomplished in the Admin UI. my javascript hack is "easy", understanding how to develop in C# not so much.

Jun 12, 2012 at 5:49 AM

There is no driver to write. Going through javascript for that is convoluted and plain wrong. You can access the Layout object from code you write in the view. It's easier than what you've done and a lot cleaner (although you could do cleaner using drivers). But eh, do as you want I suppose.

Jun 12, 2012 at 6:39 AM
Edited Jun 12, 2012 at 6:46 AM

I know it's convoluted and wrong Bertrand, that's why I asked for help. If I understood more than I do/did this thread wouldn't exist.

I think get it now..


Jun 12, 2012 at 7:24 AM

nope... call me stupid, but I'm just not able to figure this one out. better not quit my day job for this ;)

Jun 22, 2012 at 10:34 PM
Edited Jun 22, 2012 at 10:36 PM

I took a few days off to finish other tasks... I finally figured it out and it's so stupid because I've done this before in earlier Orchard testing. Sometimes my brain just over-complicates things especially when Orchard makes it all so easy. :)

Thanks again for all the help! And judging from the action in the discussions here, I have to commend you Bertrand and all the coordinators and community for offering what I think is better customer support than I've received from most paid services.

If it helps anyone else here's the alternate for the MLS input field in my "Real Estate Listing" (could be a product sku, or any other field inside a content item or part):


@using Orchard.Fields.Settings;
@using Orchard.Utility.Extensions;
    string mlsValue = (string)Model.ContentField.Value;
    if (!string.IsNullOrEmpty(mlsValue))
        string name = Model.ContentField.DisplayName;
    Layout.MyMls = mlsValue;

Now here's the view for the hidden field inside my "Request A Showing" form (hidden via css, and used to pass as the identifier in the email body so the realtor knows which property the customer wants to see):



    var mlsValue = Layout.MyMls;
<fieldset class="noshow">
    <label for="ShowingRequest_MLS_Value">
    <input type="text" id="ShowingRequest_MLS_Value" name="ShowingRequest.MLS.Value" value="@mlsValue" required="required"  class="textMedium" maxlength="15" />


Jul 5, 2012 at 9:01 AM

Hi All, Just wanted to express my thanks for this topic. I've been searching for methods to link content (especially forms) for weeks now, without massive custom coding. Your feedback has been very helpful :)