How to get page properties using sling model in aem 6.3?

Ram picture Ram · Jan 3, 2018 · Viewed 12k times · Source

I am trying to get page properties using Sling Models in AEM 6.3 but always I am getting null.

resultsRootPath = getCurrentPage().getProperties().get("ResultsRootPath", String.class);

Path of property:

/components/content/results/cq:dialog/content/items/column/items/ResultsRootPath

Could you please let me know the correct ways to property value using Sling Models?

Answer

Ramachandra A Pai picture Ramachandra A Pai · Sep 8, 2018

You can also do this:

@Model(adaptables = {SlingHttpServletRequest.class,Resource.class})
public class MyCustomModel{

    @Inject
    private InheritanceValueMap pageProperties;

    @Inject
    private ValueMap properties;

    @PostConstruct
    public void activate() {
        String pageString = pageProperties.getInherited("myproperty", "default"); //InheritanceValueMap gives pageProperties Value Map and getInherited is used to fetch a particular property.
    }

Refer this for more info: http://blogs.adobe.com/experiencedelivers/experience-management/valuemap-and-his-friend/