2

how can i access Page Template Metadata in Page View or _ Layout. I am using SDL Web 8 and DXA 1.5.

I need to add page level class on page views. There are different ways i know to implement this:-

  1. Different Page Templates with different Page Views in Code: Class will be hard coded in Page View.

Negative:- There will be lot of Page views which are not required.

  1. One Page and Create Metadata for each page to define which page is being used. Use Page metadata to assign class in View. Negative:- control to assign class goes to Editor.

  2. I want to provide Page Template Metadata and create Page Templates for each type of Page. This will be beneficial for me to create Page Types and Content Types Mapping. Also a single General Page Name can be repurposed if I can get the value of the metadata from the Page Template. Also, Editor will not be able to see the metadata. I need help with the third point i.e. how to fetch Page Template Metadata on Page View or Layout.

  • What research have you done and what have you tried? – Nickoli Roussakov Jan 20 '17 at 13:38
  • I have explained in detail the scenarios, purpose is to keep the code clean by using the third approach. however I could not find anything in Page Model, View Model and IPage to fetch Page Metadata. – Vipin Gupta Jan 20 '17 at 14:23
  • 1
    Can you elaborate on "I need to add page level class on page views"? What do you mean with that, exactly? Can you give an example? – Rick Pannekoek Jan 20 '17 at 14:45
  • A CSS class to identify PageTemplate or type of page. this is driven by UI Html Design and hence required. – Vipin Gupta Jan 27 '17 at 11:01
  • 1
    This sounds like something that DXA Framework already supports through the ViewModel.HtmlClasses property (and associated PT/CT metadata field). – Rick Pannekoek Feb 20 '17 at 20:18
1

Currently, DXA indeed does not provide a way to access Page Template metadata in Page Views OOTB; you would have to create your own Model Builder an add it to the Model Builder Pipeline to achieve this, but note that this is not an official, public extension point; it is expected to change considerably in DXA 2.0.

So, currently option 1 seems like the best option which is fully supported by the DXA Framework. I'm not sure why you say you will get many Page View which are not required; if you have different Page Models, I guess you also need different Page Views? Any commonality can be factored out in partial views (if we're talking DXA.NET).

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.