Sunday, February 7, 2016

How to Sightly in AEM / CQ

Use Case: Some common how to in Sightly

Prerequisite: Please read following document carefully before some other How to questions

Here is some common How to in sightly


  • How to include ClientLibs in Sightly 


  • How to Loop fixed number of set in Sightly 


  • How to create for or while loop in sightly

You can not have dynamic while loop directly in Sightly scripting. However you can use Use class to simulate while or for loop in Sightly. Here is example

  • How to reference other OSGI service in sightly 

You can not directly reference OSGI service in sightly template. However you can reference them in use class using getSlingScriptHelper().getService(Service.class) note that you can not use @Reference to refer a service in sightly class.

  • How to initialize a default value of a property in sightly

Best way to initialize a value is in activate method of use class. You can also do it in sightly template using something like <sly data-sly-test.parentNavName="${currentPage.properties.navTitle || currentPage.title || currentPage.pageTitle }"> and then use ${parentNavName}
  • How to access string array in Sightly 

This is pretty much similar to what we did in for loop. Here is some more generic example

  • How to create/access map in sightly 

Here is one example of how you can do that

  • How to use Sling Model with Sightly

Here is one example of how you can do it. Note that You can also create sling model for a resource and then use other use classes to return sling model.


  • How to hide element in Sightly

You can use either data-sly-unwrap or <sly> tag for this here is example
<!--/* This will only show "Foo" (without a <div> around) if the test is true: */-->
<div data-sly-test="${myTest}" data-sly-unwrap>Foo</div>

<!--/* This would show a <div> around "Foo" only if the test is false: */-->
<div data-sly-unwrap="${myTest}">Foo</div>
<!--/* This will display only the output of the 'header' resource, without the wrapping <sly> tag */-->
<sly data-sly-resource="./header"></sly>
<sly data-sly-unwrap="${false}"></sly> <!--/* outputs: <sly></sly> */-->

  • How to pass a sightly object as parameter in Sightly

More use cases to come. Please suggest me any use case you want to get clarity on.

Some more useful Link:

Tooling For Sightly:

6 comments:

  1. One of the best methods to judge the service of a site is to search for ‘myassignmenthelp review’ and go through them. Though sites like EssayShark review keep reviews on a check, students should also take up the responsibility to put reviews and testimonials after they have taken the service. These days students looking for reliable essay writing service to help them come up with brilliant writing services, essay help and assignment assistance on various topics. While one can find genuine assignment help websites like Uk essays having decent reviews posted about their services in such reliable review sites coming from the students. But is edubirdie legit? Well, that is something that one should know before availing any services from the page.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. I am an academic writer at Sample Assignment. I have gone through this piece of writing; it is quite interesting and informative as well. Well, we all know that Sample Assignment is a brand in the field of education. Generally, it helps out the students in their academic in the form of providing assignment help, assignment samples, live sessions, expert consultation etc. If you want to check for sample assignment reviews visit our website. It was incorporated in the year 2009 and since then it has been continuously assisting students in completing their assignment. It works with professional's writers who have adequate knowledge about how to deal with assignments. Also, they have years of experience as assignment provider. All our writers have worked for more than thousands of assignment papers which have helped them in understanding the importance and requirement of the assignment. Get cheap assignment help Australia from us at best price.

    ReplyDelete