1

I'm using Leprechaun for code generation and the custom field mapping I'm trying to implement isn't working. The field is generated as type String in every case, so I know the custom mapping is failing but I do not know why. I've tried the following variations:

<metadataGenerator type="Leprechaun.MetadataGeneration.StandardTemplateMetadataGenerator, Leprechaun" singleInstance="true">
    <fieldType id="{ae1b2067-94a6-4357-a997-00a5052a98fa}" type="I_AssociateBio" />
</metadataGenerator>

<metadataGenerator type="Leprechaun.MetadataGeneration.StandardTemplateMetadataGenerator, Leprechaun" singleInstance="true">
    <fieldType id="{ae1b2067-94a6-4357-a997-00a5052a98fa}" type="MySite.Feature.AssociateBio.I_AssociateBio" />
</metadataGenerator>

<metadataGenerator type="Leprechaun.MetadataGeneration.StandardTemplateMetadataGenerator, Leprechaun" singleInstance="true">
    <fieldType id="{ae1b2067-94a6-4357-a997-00a5052a98fa}" type="custom=MySite.Feature.AssociateBio.I_AssociateBio" />
</metadataGenerator>

I can tell that it's getting picked up, because firstly, the field is a Droplink so without the custom mapping it outputs as a Guid; and secondly, it shows the Field Type from my mapping in the metadata:

    /// Represents Person field
    /// <para>Field Type: custom=MySite.Feature.AssociateBio.I_AssociateBio</para>  
    /// <para>ID: {ae1b2067-94a6-4357-a997-00a5052a98fa}</para> 
    /// <para>Section: Employee Spotlight</para>
    /// </summary>
    [SitecoreField(FieldName = IEmployeeSpotlightConstants.Person_FieldName)]
    string Person { get; set; }/// <summary>

I cannot get it to output MySite.Feature.AssociateBio.I_AssociateBio Person { get; set; }

I_AssociateBio is in another project, but it's referenced in the EmployeeSpotlight project, and when I manually change the type of the field to I_AssociateBio Person it's valid

1 Answer 1

3

In the Leprechaun.config file, you'll see that the example above the metadata generator shows a "droptree". What "type" is referring to in this case is the Sitecore field type, not a C# class type

<fieldType id="{11111111-1111-1111-1111-111111111111}" type="droptree" />

In the csx file for your codegen template, there's a mapping of Sitecore field types to concrete classes: GlassMapper.csx (line 145). If the type doesn't match, it'll return string.

What you need to do is define a custom type on the fieldtype as you did above:

<fieldType id="{ae1b2067-94a6-4357-a997-00a5052a98fa}" type="associatebio" />

and then add a line in your GlassMapper.csx:

case "associatebio":
  return "MySite.Feature.AssociateBio.I_AssociateBio";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.