adobe / htlengine

An HTL (Sightly) Interpreter/Compiler for Node.js
Apache License 2.0
47 stars 20 forks source link

data-sly-template cannot be used in an external template. #86

Closed rajavijaysingh closed 4 years ago

rajavijaysingh commented 5 years ago

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

`

tripodsan commented 5 years ago

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?

raducotescu commented 5 years ago

The Sling HTL engine does not allow [0] nested templates and we've never supported this.

[0] - https://github.com/apache/sling-org-apache-sling-scripting-sightly-compiler/blame/org.apache.sling.scripting.sightly.compiler-1.1.2-1.4.0/src/main/java/org/apache/sling/scripting/sightly/impl/compiler/debug/SanityChecker.java#L102

tripodsan commented 5 years ago

thanks. so closing this as wont-fix.

karollewandowski commented 5 years ago

@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:

tripodsan commented 5 years ago

hmm..ok. I'll try to reproduce this. thanks for the clarification @karollewandowski

tripodsan commented 4 years ago

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....

adobe-bot commented 4 years ago

:tada: This issue has been resolved in version 3.2.6 :tada:

The release is available on:

Your semantic-release bot :package::rocket: