HTL file paths as variable | Community
Skip to main content
Level 2
July 27, 2021
Solved

HTL file paths as variable

  • July 27, 2021
  • 1 reply
  • 1491 views

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.
Best answer by arunpatidar

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.

1 reply

arunpatidar
Community Advisor
arunpatidarCommunity AdvisorAccepted solution
Community Advisor
July 27, 2021

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
PremIBAuthor
Level 2
July 27, 2021

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