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.
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: