Sightly sample code | Community
Skip to main content
rk39193348
Level 4
February 1, 2017
Solved

Sightly sample code

  • February 1, 2017
  • 5 replies
  • 3341 views

Hi,

Can anyone post a sample code in sightly which contains getting a node from page, resource resolver , session variable, page to node conversion so that one can understand. Please help.

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 edubey

There are many such examples available 

https://helpx.adobe.com/experience-manager/using/creating-htl-component.html

http://adobeaemclub.com/multifield-touch-ui-sightly-component/

But I would recommend you to use Sling API (Resource) instead of JCR API (Node) api.

5 replies

huzaifaha985211
Level 2
February 2, 2017

You can use javascript with slightly (html). In your JavaScript you have access to implicit objects such as PageManager, currentContent, currentSession etc. You need to create a function in your js file that returns the value such as page node etc. Once you have that then you can use slightly to pull the value from your javascript using helper object . Example of this can be found under the link below.

http://blogs.adobe.com/experiencedelivers/experience-management/htl-javascript-use-api/

edubey
edubeyAccepted solution
Level 10
February 2, 2017

There are many such examples available 

https://helpx.adobe.com/experience-manager/using/creating-htl-component.html

http://adobeaemclub.com/multifield-touch-ui-sightly-component/

But I would recommend you to use Sling API (Resource) instead of JCR API (Node) api.

Feike_Visser1
Adobe Employee
Adobe Employee
February 2, 2017

Normally this goes via Java/Javascript, however I strongly advise against the Node.class api.

It is too low-level, better to use things like the ValueMap api

rk39193348
Level 4
February 2, 2017

In JSP the below lines gives the node jcr:content, how to achieve similar thing in sightly. How to get Page from Node and iterate through the pages in sightly?? Can you please help.

 String path = "/content/usergenerated/jcr:content";

     Node node = currentPage.getContentResource().adaptTo(Node.class);
      String title = node.getName(); 
            out.println(title);

smacdonald2008
Level 10
February 3, 2017

Use the Java Sling API and Java class that extends WCMUsePojo. You can use Java API to retrieve information about JCR resources like pages.