Expand my Community achievements bar.

SOLVED

Access PageProperties from a Component + Sightly

Avatar

Level 4

[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  ?   

desktop_exl_promo_600x100_gdrp.png

1 Accepted Solution

Avatar

Correct answer by
Employee

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

${currentPage.getContentResource.getResourceType}

or

${currentPage.contentResource.resourceType}

View solution in original post

18 Replies

Avatar

Level 1

Try below:

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

 

Cheers,
Sudheera

Avatar

Level 9

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");

Avatar

Level 7

Hi,

Try this -

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

Thanks,

AryA.

Avatar

Level 4

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 

Avatar

Level 4

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 

Avatar

Correct answer by
Employee

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

${currentPage.getContentResource.getResourceType}

or

${currentPage.contentResource.resourceType}

Avatar

Level 4

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 ?

Avatar

Employee

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

Avatar

Level 3

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}

Avatar

Level 3

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

Avatar

Level 3

Any way we can do it in 6.1 . Was trying by  HTL Block Statements

<div data-sly-use.product=“/etc/commerce/product/12345”>

  ${ product.title }

</div>

Avatar

Level 2

What about getting other properties other than the title when using a jsp, such as getting the height?

Avatar

Level 2

Actually we can read the page properties in CQ as below.

${pageProperties.jcr:description}

If we enter jcr:description as some html content is page properties. How to read/handle that in sightly?  Any suggestions please?

Avatar

Employee

${pageProperties.jcr:description @ context='html'}

Avatar

Level 2

Thank u felike visser..it is working

awesome

Avatar

Level 2

Hi, Could you please exrplain when to use pageProperties,properties and currentPage .