adobe / htlengine

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

data-sly-include is not supported #226

Closed jantimon closed 4 years ago

jantimon commented 4 years ago

It looks like there is no out of the box support for data-sly-include as there is no include plugin:

https://github.com/adobe/htlengine/blob/20263b1ea0a1f9ed30e101c0bb789b985941213c/src/parser/html/MarkupHandler.js#L41-L54

Spec: https://docs.adobe.com/content/help/en/experience-manager-htl/using/htl/block-statements.html#include

Demo:

<section data-sly-include="${'./test.htl'}"></section>

Result:

Error: Plugin not implemented: include
    at MarkupHandler._lookupPlugin (htlengine/src/parser/html/MarkupHandler.js:337:11)
    at MarkupHandler._handlePlugin (htlengine/src/parser/html/MarkupHandler.js:182:30)
    at MarkupHandler.onAttribute (htlengine/src/parser/html/MarkupHandler.js:98:12)

Is there any way to declare a plugin at compile time? Is there any way to declare a plugin at runtime?

tripodsan commented 4 years ago

we might be able to support .htl script includes (but not JSP includes :-).

There are 2 possible approaches to implement this plugin:

  1. try to pre-compile the referenced script, similar to a template and then create a runtime context and execute the script. this is somewhat unelegant, since the runtime globals should not be shared with the included script.
  2. just resolve the script and add a new callback to the runtime that will invoke the script. similar to the resource resolver. The compiler could already report the expected includes, so they can be pre-compiled
jantimon commented 4 years ago

Right now my team is using only data-sly-use.

However @CodeByAlex told me that he had that issue and asked me to investigate wether it is because of the webpack loader

Probably it would be better to do 2 however if we can get the information about static resolvable scripts we could already preload templates during compile time (similar to resources)

adobe-bot commented 4 years ago

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

The release is available on:

Your semantic-release bot :package::rocket: