How to declare sightly java classes globally and include/use their references in all html files?

Avatar

Avatar

mohanr80993572

Avatar

mohanr80993572

mohanr80993572

10-10-2016

When we declare/instantiate a java class in htl/sightly in a html (similar to global.jsp) file and include it in another html, we are not able to access the reference of java class created in the included file.
For Ex:
Create a java class that extends WCMUse with some getters.

com.company.sightly.components.WcmUseSample.java

public Map<String,String> getMyHashMap() {
return myHashMap;
}

Declare/instantiate the java class in htl in a html file (similar to global.jsp)
i18n-template.html
<div data-sly-use.myClass="com.company.sightly.components.WcmUseSample" data-sly-unwrap></div>

Include it in another html and try to access the reference of java class in this html.
content.html
<div data-sly-include="i18n-template.html" data-sly-unwrap></div>
${myClass.getMyHashMap['lastpage']}

We tried many options but didn't work. Few of them are:
<div data-sly-include="i18n-template.html" data-sly-unwrap></div>

<sly data-sly-include="i18n-template.html" data-sly-unwrap></sly>

<div w3-include-html="i18n-template.html"></div>

<section data-sly-include="i18n-template.html"></section>

<section data-sly-include="${ @ path='i18n-template.html'}"></section>

<section data-sly-include="${'i18n-template.html' @ prependPath=''}"></section>

<section data-sly-include="${'' @ appendPath='i18n-template.html'}"></section>
...

Please let us know how we can achieve this. Any help would be greatly appreciated.

Thanks,

Mohan

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

Feike_Visser1

Employee

Avatar

Feike_Visser1

Employee

Feike_Visser1
Employee

11-10-2016

Answers (2)

Answers (2)

Avatar

Avatar

mohanr80993572

Avatar

mohanr80993572

mohanr80993572

12-10-2016

Thanks Feike, it worked. It is very helpful.

Avatar

Avatar

Feike_Visser1

Employee

Avatar

Feike_Visser1

Employee

Feike_Visser1
Employee

10-10-2016

I would see if extra bindings here, would do the trick. Then you don't have to include it in every HTML-file.

Example (slide 40+41) : https://adapt.to/content/dam/adaptto/production/presentations/2014/adaptTo2014-Lazy-AEM-developer-Sl...