Dynamically Update Path On data-sly-use | Community
Skip to main content
Level 5
October 22, 2019
Solved

Dynamically Update Path On data-sly-use

  • October 22, 2019
  • 1 reply
  • 1544 views

Hi,

I am calling one template using data-sly-use. below is the directory structure i have

/apps/myprj1/core/components/content/componentA/componentA.html

/apps/myprj1/core/components/content/templates/templatesA.html

Now I want to use the template in componentA.html as below. But not able to call template.

<sly data-sly-use.myTemplate="templates/templatesA.html"

     data-sly-call=""/>

Idea is during using template, avoid the project name in the path i.e. myprj1

How this can be fix.

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 Theo_Pendle

Hello,

It doesn't work because the path to the template isn't quite right You use a linux-style relative directory path to point to your templates. In your case, if you are trying to access:

/apps/myprj1/core/components/content/templates/templatesA.html

from

/apps/myprj1/core/components/content/componentA/componentA.html

Then the relative path is:

../templates/templatesA.html

Try using that instead

I reproduced it on my instance using this fix:

1 reply

Theo_Pendle
Theo_PendleAccepted solution
Level 8
October 22, 2019

Hello,

It doesn't work because the path to the template isn't quite right You use a linux-style relative directory path to point to your templates. In your case, if you are trying to access:

/apps/myprj1/core/components/content/templates/templatesA.html

from

/apps/myprj1/core/components/content/componentA/componentA.html

Then the relative path is:

../templates/templatesA.html

Try using that instead

I reproduced it on my instance using this fix: