Access PageProperties from a Component + Sightly | Community
Skip to main content
October 16, 2015
Solved

Access PageProperties from a Component + Sightly

  • October 16, 2015
  • 18 replies
  • 56411 views

[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.
Best answer by Feike_Visser1

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

${currentPage.getContentResource.getResourceType}

or

${currentPage.contentResource.resourceType}

18 replies

October 16, 2015

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");
Dinu_Arya
October 16, 2015

Hi,

Try this -

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

Thanks,

AryA.

October 16, 2015

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 

October 16, 2015

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 

Feike_Visser1
Adobe Employee
Feike_Visser1Adobe EmployeeAccepted solution
Adobe Employee
October 16, 2015

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

${currentPage.getContentResource.getResourceType}

or

${currentPage.contentResource.resourceType}

October 16, 2015

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 ?

Feike_Visser1
Adobe Employee
Adobe Employee
October 16, 2015

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

sudheeras
October 16, 2015

Try below:

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

 

Cheers,
Sudheera

ebin_Aby
July 24, 2017

How can I access node properties of different nodes. (directly by HTL , not by js or java )

something like this ?

<div id="data" data-sly-use.tesr="/etc/ttt">

  ${tesr.count}

ebin_Aby
July 24, 2017

How can I access node properties of different nodes? ( not current page, directly by HTL , not by js or java )