AEM Code Snippets

How to use a sling service in sightly page without using javascript?

When you try to access sling.getService() in Sightly you will see compilation error "sling cannot be resolved". 
So this can be achieved in sightly using below code snippet.

public class Search extends WCMUse {

    SearchService service

    @Override
    public void activate() throws Exception {
        service = getSlingScriptHelper().getService( SearchService.class );
    }

For AEM 6.2 we can get the service as below
<p data-sly-use.search="com.your.package.SearchServiceImpl">
   ${search.results}
</p>
========================================================================================================

3 comments :

  1. I really appreciate the information shared above. It’s of great help. If someone wants to learn Online (Virtual) instructor lead live training in #VEEVA #CRM, kindly contact us http://www.maxmunus.com/contact
    MaxMunus Offer World Class Virtual Instructor-led training on #VEEVA #CRM. We have industry expert trainer. We provide Training Material and Software Support. MaxMunus has successfully conducted 100000+ pieces of training in India, USA, UK, Australia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain, and UAE etc.
    Avishek Priyadarshi
    MaxMunus
    E-mail: [email protected]
    Skype id: avishek_2.
    Ph:(0) 8553177744 / 080 - 41103383
    http://www.maxmunus.com/

    ReplyDelete
  2. I really appreciate the information shared above. It’s of great help. MaxMunus provides Remote Support For Corporate and for Individuals. If anyone is facing any issue in his project of #VEEVA #CRM we can support them remotely , kindly Contact MaxMunus
    MaxMunus Offer World Class Industry best Consultant on #VEEVA #VEEVA. We provide end to end Remote Support on Projects. MaxMunus is successfully doing remote support for countries like India, USA, UK, Australia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain, and UAE etc.
    Avishek Priyadarshi
    MaxMunus
    E-mail: [email protected]
    Skype id: avishek_2.
    Ph:(0) 8553177744 / 080 - 41103383
    www.MaxMunus.com

    ReplyDelete
  3. Hello,
    I have to build a curl command for setting up the replication agent from author to publisher. Can you help me out.

    ReplyDelete