Closed ismay closed 6 years ago
:+1:
Strange that var template = nunjucks.compile(str, env, opts.filename || null, true);
isn't applying the path correctly.
https://mozilla.github.io/nunjucks/api.html#compile
Yeah, it seems like it should be working.
Hey @RobLoach, just wondering if there's any news on this bug. Had someone run into it again: https://github.com/superwolff/metalsmith-in-place/issues/69
Found that you can use .configure(path)
to somehow set a root directory. We may be able to have options.root
become that base directory for templates.
Any progress on this issue? Seeing the same with extends
{% extends "../layouts/layout.njk" %}
Attempted over at https://github.com/jstransformers/jstransformer-nunjucks/pull/16 .
Any luck with this issue?
https://github.com/jstransformers/jstransformer-nunjucks/blob/master/index.js#L16
Think we should fix up the path detection a bit better? Any thoughts? Did some work on this, but it could likely be better.
This configuration works for me (in metalsmith):
const metalsmith = require('metalsmith');
const inPlace = require('metalsmith-in-place');
metalsmith(__dirname)
.source(`${__dirname}/src/views`)
.destination(`${__dirname}/dist`)
.use(inPlace({
engineOptions: {
root: `${__dirname}/src/views`
}
}))
.build(function(err){
if (err) throw err;
});
So I guess you just have to explicitly pass the root
See this test repo: https://github.com/ismay/nunjucks-include
Running
node index.js
:Demonstrates how includes work for files on the same level, or below it, but fail for includes of files located above the parent. It fails with the following error:
Could not find anything in the nunjucks' documentation indicating that this should not work. Any idea whether this is related to this lib, or is it nunjucks related?
The weird thing is that the path in the error
Error: template not found: /Users/ismay/Projects/nunjucks/lib/include.html
exists..