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.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:


  1. I definitely enjoying every little bit of it. It is a great website and nice share:
    contact form | snapchat emoji

  2. When life gives you a hundred reasons to cry, show life that you have a thousand reasons to smile.
    Friv2Games, Kizi 6 Games, Yepi Games, Unblocked Craft, Friv, Y8Y8co, Y3 Game, Frozen Games, Y8Y8, Kizi, tetris battle, Friv, Y8Y8 co

  3. this is usually the

    content to make the

    groundwork on holiday within the next originating intake. our team tend to be among the best and even prime

    market study on holiday consultancies with

    regard to India with good visa self-assurance. back in actually much

    less time our team help file a f1 visa. people around the globe are unquestionably

    also assist you actually by

    means of help and foreign education consultants in hyderabad advice is required to make application

    for the school environs.