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:

7 comments:

  1. This comment has been removed by the author.

    ReplyDelete

  2. This shows what impact does different negative and fake reviews of services and how it can affect the business. Reviews or testimonials regarding any service are the only way to get an idea about its quality and credibility. My Assignment Help Review feedbacks from students all over the world. MyAssignmenthelp.com reviews show the dedication and efforts the company put to ensure 100% quality. Although most of the reviews are positive, but there are testimonials with negative feedback as well. It is needless to say that if the students are convinced that edubirdie.com review is not a good, they will definitely not opt for it. Therefore, if the number of negative and fake reviews is increased on reputed sites like MyAssignmentHelp Review, the sale can rapidly get down. To counter this issue, the only way is to go through or read that are posted on the site, However, essayshark review and Ukessays review posted on the sites are very small.

    ReplyDelete
  3. Nice post! Thanks for posting….

    http://universalpackersthane.com

    ReplyDelete