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?

1 Answer 1

12

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.

2
  • 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. Commented Sep 19, 2017 at 18:51
  • Thanks Rick, I never used the PageModel.Meta. The answer is updated with this info.
    – Jan H
    Commented Sep 20, 2017 at 6:28

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.