Import/Export Data: Position Matters!

Just ran a test to determine why my data wasn’t showing up after importing elements into an Orchard site.  Ran a comparison from the data that was built manually into the site, and the data that was imported:  I discovered the only difference in the data for the Content Types was the Common_IdentityPartRecord.Id field was different (swapped) for some content items.  I went back to my import package (xml file) and rearranged the content so that the order flowed logically (ContentType Parent created first, then ContentType Child, then Widget instead of ContentType Child, then Parent then Widget like the Export Feature ordered them) and presto!  The data for my control is now rendering!

No explanation as of yet why this is the case.  This cost me some considerable time to troubleshoot and I wanted to post this to assist anyone trying to figure out why their data from using the import feature is imported, but your site still may not work as expected.

When control was built manually and it works the Common_IdentityPartRecord table looked like this:


When imported, table looks like:



Solved: Projector Module Layout to display Media Picker Field as Image

So I ran into a problem a couple of days ago, and jumped on StackOverFlow hoping I could get a quick and painless answer.  I wanted to use the snazzy new Projector Module to both simplify my life and confer to the site administrator a great sense of managing a site without the need to call for a developer.  The Projector Module was going to solve my problem of displaying a list of “Our People” on an About Us Page.  So, I created a Content Type, OurPeople, complete with a FirstName, LastName, Avatar, Professional and Personal Biography, etc.  Then I created a Query to select all OurPeople Content Types with an Active Field set to true.  My next step involved adding a new layout to display the fields I wanted in the manner that I wanted.  All of this is splendidly accomplished through the Project Module.  Then I hit a little problem:  My Avatar, which is a MediaPickerField, would only display the link and not produce an image.  I used the Rewrite Results option of the Property Field to convert the URL into an image that would display on the page, but discovered the tilde (~/Media/../picture.jpg) from the {Text} token did not get converted to the relative Url path and, as a result, did not find the image.


Problem:  Converting the tilde (~)  from MediaPickerField to the necessary relative path?

The solution appears to be figuring out how to get the {Text} token field to display the relative resolved path of the image provided by the MediaPickerField.  Or instead of using the {Text} token using some other token to achieve the result.


With that in mind, I went to the code and peeked around until I stumbled across the code for creating the tokens.  A few hours later, I figured out that if I include two lines of code in the ContentToken.cs file (Orchard.Tokens/Providers/ContentToken.cs), I could effectively get the results I was anticipating.


I added a line of code that creates a Url Token to be used for a MediaPickerField in the Describe method of the ContentTokens class:


Then I added a line of code in the Evaluate method of the ContentTokens class to retrieve the value from the MediaPickerField and convert it using the System.Web.MVC UrlHelper class’ Content method:


Now Instead of referencing the {Text} token, I reference the MediaPickerField with the following token:

<img class="our-people-avatar" src="{Content.Fields.OurPeople.Avatar.Url}" alt="" />

Where “OurPeople” is the ContentType being referenced, “Avatar” is the MediaPickerField being referenced and “Url” is the newly created token that converts the tilde into a relative path!


Now by no means do I consider myself being adept enough in understanding all that encompasses the Orchard CMS.  This was simply a problem I ran into and a solution that has so far worked for me.  If any Orchard experts read through this post, and would like to offer any feedback as to whether this would be the recommended way to solve the problem or not, I would love to hear from you.  I have not contributed this to the project because, again, I’m a newbie and don’t care to be ridiculed or ostracized for doing something incorrectly (if that is indeed what the superior intelligence takes levity in).