data-sly-template cannot be used in an external template.
Closed this issue ยท 7 comments
Currently in the call_spec.txt, the test to validate "sightly call function can call other templates" is working, but when the same is done by having the templates loaded using data-sly-use, it is not working
in the templateLib.html
added the below snippet
<template data-sly-template.foo="${@ a}"><div data-sly-use.lib="templateLib1.html" data-sly-call="${lib.bar @ a=a}"></div></template>
created a new file templateLib1.html
under template_spec
folder with the below code
<template data-sly-template.bar="${@ a}"><section>${a}</section></template>
and if we test with the below snippet
<div data-sly-use.lib="template_spec/templateLib.html" data-sly-call="${lib.foo @ a=123}"></div>
we are getting error
`
Error: Template cannot be defined in another template
at JSCodeGenVisitor.visit (...\htlengine\src\compiler\JSCodeGenVisitor.js:146:15)
at Start.accept (...\htlengine\src\parser\commands\Command.js:29:13)
at commands.forEach (...\htlengine\src\compiler\JSCodeGenVisitor.js:76:9)
at Array.forEach ()
at JSCodeGenVisitor.process (...\htlengine\src\compiler\JSCodeGenVisitor.js:75:14)
at Compiler.compile (...\htlengine\src\compiler\Compiler.js:235:8)
at
`
the current engine does not allow to specify a template in another template.
from the spec it's not clear if this is allowed or not: https://github.com/adobe/htl-spec/blob/master/SPECIFICATION.md#22101-template
@raducotescu is this allows in the sling htl engine?
The Sling HTL engine does not allow [0] nested templates and we've never supported this.
thanks. so closing this as wont-fix.
@tripodsan, I think it is not about nested templates, but template calling another template. Correct me if I'm wrong, but I understand that the code @raducotescu pasted is to detect cases like:
<template data-sly-template.foo="${@ a}">
<template data-sly-template.bar="${@ a}">
template code
</template>
</template>
The bar
is disallowed nested template in this snippet.
In Sling based application I created:
test/component.html
:
<div data-sly-use.lib="templatesLib.html" data-sly-call="${lib.foo @ a=123}"></div>
test/templatesLib.html
:
<template data-sly-template.foo="${@ a}">
<div data-sly-use.lib="templatesLib1.html" data-sly-call="${lib.bar @ a=a}"></div>
</template>
test/templatesLib1.html
:
<template data-sly-template.bar="${@ a}">
<section>${a}</section>
</template>
I think this is the case that @rajavijaysingh wanted to report and in Sling it works without any issues.
hmm..ok. I'll try to reproduce this. thanks for the clarification @karollewandowski
I see...you can move the lib outside of the <template/>
element:
<sly data-sly-use.lib="templatesLib1.html" />
<template data-sly-template.foo="${@ a}">
<div data-sly-call="${lib.bar @ a=a}"></div>
</template>
but I see if I can split the statements internally....
๐ This issue has been resolved in version 3.2.6 ๐
The release is available on:
Your semantic-release bot ๐ฆ๐