SDL DXA Component Links In Page Metadata

In my DXA solution I was trying to change the Page Metadata to come from a Component rather but unfortunately it didn’t work out of the box.

tridion-page-metadata

Taking a look inside the ProcessMetadataField method in the DefaultModelBuilder class the code is written to work with an Embedded Schema:

if (field.FieldType==FieldType.Embedded)

But when it drops into the else statement to resolve the Component Link then it doesn’t get any content back as that Page Metadata Component is not published.

With a quick tweak to the method you can add an extra else if for a Component Link type and this is now working:

else if (field.FieldType == FieldType.ComponentLink)
{
    foreach (IComponent component in field.LinkedComponentValues)
    {
       foreach (IField subfield in component.Fields.Values)
       {
         ProcessMetadataField(subfield, meta, localization);
       }
    }
}

I also needed to change the link level value to 2 in the Generate dynamic page TBB on the Render Page Content Modular Template in order to get the Metadata Component values in the published JSON:

link-level-getpagecontent

SDL DXA Component Links In Page Metadata

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s