Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to parse variable inside twig include #17

Open
rud-wtag opened this issue Sep 19, 2023 · 3 comments
Open

Unable to parse variable inside twig include #17

rud-wtag opened this issue Sep 19, 2023 · 3 comments

Comments

@rud-wtag
Copy link

rud-wtag commented Sep 19, 2023

Hi, I was trying to import another twig template by using template path inside a twig variable

both of these code snippet are failing to do so (while in Drupal 10 twig it's woking fine):

Snippet 1

{% set test = "./components/code-snippet/code-snippet.twig" %}
{% include(test) %}

Snippet 2

{% set test = "./components/code-snippet/code-snippet.twig" %}
{% include test %}

Throwing below error:

ModuleBuildError: Module build failed (from ./node_modules/twigjs-loader/index.js):
NonErrorEmittedError: (Emitted value instead of an instance of Error) TwigException: Unable to parse 'include(test)'
    at processResult (/app/node_modules/webpack/lib/NormalModule.js:761:12)
    at /app/node_modules/webpack/lib/NormalModule.js:866:5
    at /app/node_modules/loader-runner/lib/LoaderRunner.js:400:11
    at /app/node_modules/loader-runner/lib/LoaderRunner.js:252:18
    at runSyncOrAsync (/app/node_modules/loader-runner/lib/LoaderRunner.js:156:3)
    at iterateNormalLoaders (/app/node_modules/loader-runner/lib/LoaderRunner.js:251:2)
    at /app/node_modules/loader-runner/lib/LoaderRunner.js:224:4
    at /app/node_modules/webpack/lib/NormalModule.js:840:15
    at Array.eval (eval at create (/app/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:12:1)
    at runCallbacks (/app/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:43:15)
    at /app/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:249:5
    at /app/node_modules/graceful-fs/graceful-fs.js:123:16
    at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3)
    at processResult (/app/node_modules/webpack/lib/NormalModule.js:764:19)
    at /app/node_modules/webpack/lib/NormalModule.js:866:5
    at /app/node_modules/loader-runner/lib/LoaderRunner.js:400:11
    at /app/node_modules/loader-runner/lib/LoaderRunner.js:252:18
    at runSyncOrAsync (/app/node_modules/loader-runner/lib/LoaderRunner.js:156:3)
    at iterateNormalLoaders (/app/node_modules/loader-runner/lib/LoaderRunner.js:251:2)
    at /app/node_modules/loader-runner/lib/LoaderRunner.js:224:4
    at /app/node_modules/webpack/lib/NormalModule.js:840:15
    at Array.eval (eval at create (/app/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:12:1)
    at runCallbacks (/app/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:43:15)
    at /app/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:249:5
    at /app/node_modules/graceful-fs/graceful-fs.js:123:16
    at FSReqCallback.readFileAfterClose [as oncomplete] (node:internal/fs/read_file_context:68:3)
@megahertz
Copy link
Owner

Unfortunately, dynamic import isn't supported

@koheiiwamura
Copy link

Thank you for continuously adding new features.

Since the use of the include function is becoming a recommended approach, it would be great if twigjs-loader could support it as well.

https://twig.symfony.com/doc/3.x/tags/include.html

It is recommended to use the include function instead as it provides the same features with a bit more flexibility:

#17
https://stackoverflow.com/questions/15566167/twig-tag-include-vs-function-include

@megahertz
Copy link
Owner

TBH, I don't know how to implement it. So, any PR is appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants