Issues with embed tag
Created by: lionel87
Hi!
I am a bit confused after an error message, I suspect something is buggy in the {% embed %} tag.
Versions: twing: 4.0.2 node: v12.13.0
My code looks like this:
{# twig/main.twig #}
{% embed "layout/embed.twig" %}
{% block content "hello" %}
{% endembed %}
{# twig/layout/embed.twig #}
A{% block content 'world' %}A
// index.js
const path = require("path");
const { TwingEnvironment, TwingLoaderFilesystem } = require("twing");
async function main(d) {
const loader = new TwingLoaderFilesystem(path.resolve(__dirname, "twig"));
const twig = new TwingEnvironment(loader, { debug: true });
const content = await twig.render("main.twig", {});
console.log(content);
}
main().catch(console.error);
The error I get is the following:
TwingErrorLoader: Unable to find template "/test/twig/main.twig" (looked into: /test/twig) in "/test/twig/main.twig" at line 1.
at /test/node_modules/twing/dist/cjs/lib/loader/filesystem.js:211:39
at async Promise.all (index 0)
at async Object.doDisplay (eval at getTemplatesModule (/test/node_modules/twing/dist/cjs/lib/environment.js:492:24), <anonymous>:24:80)
at async main (/test/index.js:7:21) {
rawMessage: 'Unable to find template "/test/twig/main.twig" (looked into: /test/twig).',
source: TwingSource {
code: '{% embed "layout/embed.twig" %}\n' +
' {% block content "hello" %}\n' +
'{% endembed %}\n',
name: '/test/twig/main.twig'
},
previous: undefined,
name: 'TwingErrorLoader',
lineno: 1
}
When I use a simple include tag instead of the embed tag everyting is fine, the file gets included from the same directory. But with embed, this error occurs.
Also the error here that states main.twig is missing is a bit confusing for me. Why does it references the main.twig with absolute path?
Previously we used the 2.3.7 version of twing, which does not contain this bug (or feature).
Thanks!