Skip to main content
Level 5
10月 22, 2019 12:39 下午 UTC
已解決

Dynamically Update Path On data-sly-use

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.

此主題已關閉回覆。
Theo_Pendle
Level 8
10月 22, 2019 6:48 下午 UTC

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 則回覆

Theo_Pendle
Level 8
10月 22, 2019 6:48 下午 UTC

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:

翻譯