8

Is it possible to access the PageModel metadata from an Entity View level? I don't see any properties on the entity model @Model that expose the PageModel or Page Metadata.

I've seen this post about DD4T, in DD4T the ComponentPresentation.Page property gives access to the whole page. Does DXA have something similar?

11

The page model is available in an entity view though the WebRequestContext.

@WebRequestContext.PageModel

It is considered bad practice though to use page data in your entity view. It is code smell, sounds like the content model is not ideal.

The page metadata fields are available as well in PageModel.Meta.

@WebRequestContext.PageModel.Meta["description"]

Even better, you can make your own strongly typed model add properties for the metadata fields you would like to use.

Edit: added page model metadata.

  • 1
    The standard Page Model does have a Meta property which also provides (loosely typed) access to Page metadata, but it is indeed better to create your own strongly typed Page Model class and use senantic mapping to the Page metadata. – Rick Pannekoek Sep 19 '17 at 18:51
  • Thanks Rick, I never used the PageModel.Meta. The answer is updated with this info. – Jan H Sep 20 '17 at 6:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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