dd4t

DD4T - How to access Publication Metadata Fields?


On my project I have publication and page metadata which is being consumed in the view. For example, my page metadata looks something like this in the view:

@model DD4T.ContentModel.IPage
....
@if (Model.MetadataFields.ContainsKey("browserTitle")) {
    <title>@Model.MetadataFields["browserTitle"].Value</title>
}

Is there a corresponding way to access the page's publication metadata?

I do see that the IPage model has Publication.Id available but I'm unsure of how to use it to retrieve publication metadata?

Thanks


Solution

  • Publication metadata is not available in the DD4T object model. The work-around is to create a DD4T template class in .NET which reads the metadata from the publication and stores it in the page. In the web app you can retrieve the information from the page metadata.

    There is a template class in DD4T called 'Add inherited metadata to page', which does the same for structure group metadata (not publication metadata). You can check out the source and use this as a starting point.