Expand my Community achievements bar.

Radically easy to access on brand approved content for distribution and omnichannel performant delivery. AEM Assets Content Hub and Dynamic Media with OpenAPI capabilities is now GA.

Sightly variables scope

Avatar

Level 7

Hi all,

 

I used to have a jsp file for global variables. Is there an equivalent in sightly?

 

Suppose I have

 

public class AbstractModel{

    @PostConstruct

     public void init(){

         // -- initiate all base variables

     }

     public String getModelName()

     {

           return AbstractModel.class.getName();

     }

}

 

public class AbstractPage extends AbstractModel{

    @PostConstruct

     public void init()

     {

      // more vars here for page templates

     }

}

 

public class NewsLandingPage extends AbstractPage{

    // blah blah

}

 

public class NewsComponent extends AbstractModel{

    // blah blah

}

 

HTL templates

global.html 

<sly data-sly-use.abm="my.site.AbstractModel"/>

<sly data-sly-use.abPage="my.site.pages.AbstractPage"/>

<!--/* other customized global variables */-->

<!-- global info: ${abm.modelName }-->

 

for newslanding

newslanding.html

<sly data-sly-include="global.html"/>

<!-- newslanding info: ${abm.modelName} -->

 

Output:

<!-- global info: my.site.AbstractModel -->

<!-- newslanding info: -->

 

I would expect both to return the same name, but the landing page fails. How can I extend the global visibility to other files? 

Thank you very much!

 

-kt

4 Replies

Avatar

Employee Advisor

Hi,

 

To extend the visibility of global variables in Sightly, you can use the data-sly-template and data-sly-call directives. Create a global template file with the variables and include it in your specific templates using data-sly-call to access the variables.

Avatar

Level 7

Thanks, but it looks like template and data-sly-call is different from what I am trying to achieve.

 

sly-template looks to me as a nested template, I actually need the opposite. 

 

<sly data-sly-use.tpl="${'template.html'}" data-sly-call="${tpl.include @ tplVar=something}"/>, then the emphasis is on template.html.

 

The opposite is I need a global file can be shared with many resource templates. 

 

 

Avatar

Employee

Hi @kevingtan 

I don't think there is any such global file in Sightly as it used to be with JSP's. You can try checking below:

https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/aem-sightly-include-html-p...

Avatar

Level 7

Thanks for the input. I figure sly-template is not what I need.