Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

HTL file paths as variable

Avatar

Level 2

In some of my HTL files i am using a use api script, which is in path /apps/level1/level2/file.js. To call this script from my HTL file, i am using the following code.

<div data-sly-use.file="${'/apps/level1/level2/file.js' @ args=something}">${file}</div>

 

I am doing the same thing at different parts of the same or different HTL file. is there anyway i could use a seperate template like file to store these paths, then call them at the necessary HTL files like.

<sly data-sly-include.variable="variables.html"/>

//rest of the code

<div data-sly-use.file="${variable.file1 @ args=something}">${file}</div>
1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi,

you can use within a file but from another file. data-sly-include, replaces the content of the host element with the markup generated by the indicated HTML template file (HTL, JSP, ESP etc.) when it is processed by its corresponding template engine. The rendering context of the included file will not include the current HTL context (that of the including file);

 

<data-sly-set.api="${'test.js'}" />
<sly data-sly-use.product="${api}" />

 

you can try using data-sly-template

  • data-sly-template you declare templates which can later be 'called' with data-sly-call.


Arun Patidar

View solution in original post

5 Replies

Avatar

Correct answer by
Community Advisor

Hi,

you can use within a file but from another file. data-sly-include, replaces the content of the host element with the markup generated by the indicated HTML template file (HTL, JSP, ESP etc.) when it is processed by its corresponding template engine. The rendering context of the included file will not include the current HTL context (that of the including file);

 

<data-sly-set.api="${'test.js'}" />
<sly data-sly-use.product="${api}" />

 

you can try using data-sly-template

  • data-sly-template you declare templates which can later be 'called' with data-sly-call.


Arun Patidar

Avatar

Level 2

@arunpatidarthanks for the reply. can you provide me an example? it would be really helpful.

Avatar

Level 2
@arunpatidar sorry for the late reply. I tried to add data-sly-set.foo="valuee" in a template file and called it from my other HTL file. Even with this process the HTL context of templates seems to be lost, Only the generated Markup is received in the host HTL file.

Avatar

Community Advisor
Hi, you can call the template with param and rendering will be done in the template, it is like a function but without return


Arun Patidar