HTL file paths as variable | Community
Skip to main content
Level 2
Jul 27, 2021 1:04 PM UTC
Solved

HTL file paths as variable

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>
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
arunpatidar
arunpatidarAccepted solution
New Participant
Jul 27, 2021 2:36 PM UTC

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

5 replies

arunpatidar
arunpatidarAccepted solution
New Participant
Jul 27, 2021 2:36 PM UTC

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.
Translate
Arun Patidar
PremIBAuthor
Level 2
Jul 27, 2021 2:49 PM UTC

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

Translate