Display Baked In CustomProperties

Topics: Customizing Orchard, General, Writing modules
Sep 28, 2011 at 3:08 PM
Edited Sep 28, 2011 at 4:24 PM

I'd like to display some data stored in the Custom Properties fields that come baked in with Orchard.  I think I'm getting turned around looking at the Orchard.Core\Containers.  From what I can tell I need to write a Display() function in the CustomPropertiesDriver.cs, add a CustomPropertiesViewModel.cs and a coresponding razor view.  Am I on the right track here?  

This is what I have for the Display() function:

protected override DriverResult Display(Containers.Models.CustomPropertiesPart Part, string displayType, dynamic shapeHelper)
{
	return Combined(ContentShape("Parts_CustomProperties", () => shapeHelper.CustomProperties(ContentPart: Part)));
}

CustomPropertiesViewModel.cs:

using System.Web.Mvc;
 
namespace Orchard.Core.Containers.ViewModels
{
	public class CustomPropertiesViewModel
	{
		public string CustomOne { getset; }
		public string CustomTwo { getset; }
		public string CustomThree { getset; }
	}
}

razor view (CustomProperties.cshtml):

<div class="custom-properties-one">@Model.CustomOne</div>
<div class="custom-properties-two">@Model.CustomTwo</div>
<div class="custom-properties-three">@Model.CustomThree</div>

I also added this to the Placement.info:

<Place Parts_CustomProperties="Content"/>

Everything seems to run fine but the data is not being displayed (grr).  I appreciate all the help on here! -adrian

Coordinator
Sep 28, 2011 at 4:49 PM

Are you saying you modified the code in Orchard.Core? If so, you should not. Write a module instead. If you just need to access the values of those fields from some template, it's probably simpler to just do this: @Model.ContentItem.CustomPropertiesPart.Record.CustomOne