I'm having some trouble mapping to a Rules
data field in Sitecore. I've got a rendering parameters template that has a data field named "Redirect Rules."
I'm using TDS and Glass to map the objects back to Sitecore. In the generated class, I get the following:
/// <summary>
/// The Redirect Rule field.
/// <para></para>
/// <para>Field Type: Rules</para>
/// <para>Field ID: 659373d6-c5c5-4851-aa1f-066f53218780</para>
/// <para>Custom Data: </para>
/// </summary>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Team Development for Sitecore - GlassItem.tt", "1.0")]
[SitecoreField(IMy_Name_Rendering_ParametersConstants.Redirect_RuleFieldName)]
public virtual object /* UNKNOWN */ Redirect_Rule {get; set;}
When I attempt to get the value of the "Redirect Rules" field in my view rendering via
GetRenderingParameters<My_Name_Rendering_Parameters>();
the "Redirect Rules"property is null. I have verified that the field is populated with rules by examining it in the Experience Editor.
Any clue to what might be going on?
Craig. Look here for a modified T4 template that maps the Rules field to a string value: https://gist.github.com/patrickperrone/9626cccbd044cc418539
Here is my blog post that covers this in a little more detail.
Excerpted from my post:
The basic issue is that the glassv3item.tt template doesn't know how to deal with the
Rules
field. TheGetGlassFieldByType
method is responsible for assigning a type to mapped field. It does this with aswitch
statement. Our rules field is falling all the way through to thedefault
case which maps the field to anobject
. We need to add a case for thefield.Type
value when it equals "rules".
Short answer: I use a string
type as my mapped field.Type
when value equals "rules".
You can see this for yourself on lines 246-247 here.