Access PageProperties from a Component + Sightly | Community
Skip to main content
Level 4
Oct 16, 2015 2:29 AM UTC
Solved

Access PageProperties from a Component + Sightly

[Thread Edited By Adobe]

/*Don’t forget to meet and greet your fellow peers virtually by telling them about yourself here. 

Go ahead and to it now: https://adobe.ly/3eDnB4v */

 

Actual Question:

In JSP I have used (currentPage.getContentResource()).getResourceType() to access resourcetype of a template from a component.

In sightly I wondered if we can access the same using ${pageProperties}

I am trying following from the component.html , and I get empty String Values

${pageProperties.cq:designPath} <br/>

${pageProperties.jcr:title} <br/>

${pageProperties.sling:resourceType} <br/>

How can I do this in Sightly  ?   

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Feike_Visser1
Feike_Visser1Accepted solution
Employee
Oct 16, 2015 2:29 AM UTC

If you have this in JSP, you can do it like this in Sightly:

${currentPage.getContentResource.getResourceType}

or

${currentPage.contentResource.resourceType}

18 replies

sudheeras
New Participant
Oct 16, 2015 2:29 AM UTC

Try below:

${currentPage.title}
${currentPage.path}

 

Cheers,
Sudheera

Translate
Level 9
Oct 16, 2015 2:29 AM UTC

Hi, 

Not quite sure if this helps, but just pasting it across[it looks like probably there are other two methods available].

There are three methods to access content in AEM WCM:

  • Via the properties object introduced in global.jsp:
    The properties object is an instance of a ValueMap (see Sling API) and contains all properties of the current resource.
    Example: String pageTitle = properties.get("jcr:title", "no title"); used in the rendering script of a page component.
    Example: String paragraphTitle = properties.get("jcr:title", "no title"); used in the rendering script of a standard paragraph component.
  • Via the currentPage object introduced in global.jsp:
    The currentPage object is an instance of a page (see CQ5 API). The page class provides some methods to access content.
    Example: String pageTitle = currentPage.getTitle();
  • Via currentNode object introduced in global.jsp:
    The currentNode object is an instance of a node (see JCR API). The properties of a node can be accessed by the getProperty() method.
    Example: String pageTitle = currentNode.getProperty("jcr:title");
Translate
Dinu_Arya
Level 6
Oct 16, 2015 2:29 AM UTC

Hi,

Try this -

${pageProperties['cq:designPath']} <br/>
${pageProperties['jcr:title']} <br/>
${pageProperties['sling:resourceType']} <br/>

Thanks,

AryA.

Translate
Level 4
Oct 16, 2015 2:29 AM UTC

Dinu_Arya wrote...

Hi,

Try this -

${pageProperties['cq:designPath']} <br/>
${pageProperties['jcr:title']} <br/>
${pageProperties['sling:resourceType']} <br/>

Thanks,

AryA.

 

This did not work for me , when I use this on my component.html :(.

I still see the empty strings 

Translate
Level 4
Oct 16, 2015 2:29 AM UTC

sudheeras wrote...

Try below:

${currentPage.title}
${currentPage.path}

 

Cheers,
Sudheera

 

I tried this as well. I am still not able to access these page Properties 

Translate
Feike_Visser1
Feike_Visser1Accepted solution
Employee
Oct 16, 2015 2:29 AM UTC

If you have this in JSP, you can do it like this in Sightly:

${currentPage.getContentResource.getResourceType}

or

${currentPage.contentResource.resourceType}

Translate
Level 4
Oct 16, 2015 2:29 AM UTC

Feike Visser wrote...

If you have this in JSP, you can do it like this in Sightly:

${currentPage.getContentResource.getResourceType}

or

${currentPage.contentResource.resourceType}

 

I checked with my colleague its working for him. 

Do I need to install any new hot fix / service pack ? for Sightly to work fine ?

Translate
Feike_Visser1
Employee
Oct 16, 2015 2:29 AM UTC

This is basic/core functionality of Sightly, no need for add-ons here.

Translate