twig.js
twig.js copied to clipboard
Namespaces with source() do not resolve
Hello
When I include a partial with include tag it's work really well
{% include '../partials/_exemple.twig' %}
But when I use source tag with same path,
{{ source('../partials/_exemple.twig') }}
It displays :
Template "../partials/_exemple.twig" is not defined.
It should display partial content without interpreting it.
This is because of 4012 in twig.js. It's asking for:
if (isNodeEnvironment) {
loader = 'fs';
path = __dirname + '/' + name;
} else {
loader = 'ajax';
path = name;
}
Which then gives you: /Users/xyz/your_application/bin/node_modules/twig
It should be using the path shared by Node's Twig implementation.
I'm encountering the same issue. Has anyone figured out a fix (maybe re-implementing the "source" tag as a custom function)?
Here is the most simple implementation of the source
function which worked for my use case. Eventually the dir
will probably need to be adapted.
const dir = __dirname;
Twig.extendFunction('source', function(src) {
return fs.readFileSync(dir + src, 'utf8');
});
This may be fixed via https://github.com/twigjs/twig.js/pull/526 . Mind re-testing?
Now source function works if you use a path relative to the root of the project, however the source function does not support namespaces as it does with Twig
Not sure if this issue should be open for this or if other issue should be created
Real bummer here. Does it take much effort to implement that? I can also create a PR if you point me to the gap in the code that has to be filled.
bump, any update on this one?