-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
How do I specify the base path for templates? #14
Comments
+1 Right now, gulp-nunjucks uses the base path of the file that was passed to the plugin as the first argument that is passed to the nunjucks.FilesystemLoader constructor. This means that it is impossible to for instance include any files that live in any parent directory. Maybe allow specifying |
@slavafomin You can work around it by passing a nunjucks.Environment in the options to compile like so:
This base path will be used for all your require and extend statements. |
Yup, that's the correct way to do it, else it falls back to |
Thanks @wolthers, for a suggestion! I've found this module to have better API and more options: And it has |
A slightly cleaner way around this can be achieved by using gulp-base: .pipe(base('src'))
.pipe(nunjucks.compile())
.pipe(base('src/html')) |
If you get TypeError: nunjucks.FileSystemLoader is not a constructor That is probably because you imported const nunjucks = require('gulp-nunjucks'); You need to import the original const nunjucks_lib = require('nunjucks'); And usage could be like gulp.src('some-base-path/file.template')
.pipe(nunjucks.compile(data,{
env: new nunjucks_lib.Environment(new nunjucks_lib.FileSystemLoader('some-base-path'))
}))
// ... |
After around 5 years I've stumbled upon the same problem and had to use another package again :) By the way, I still don't understand why this issue was closed. |
After so many hours of investigation I've found out that all I had to do was add a second argument to the gulp.src('./docs/homepage/index.html', {base: './docs'}) Because then I was able to include files in my templates which where outside the |
Hello!
Thank you for this great library!
However, how do I specify the base path for templates? The
opts
here doesn't have such option.Thanks!
The text was updated successfully, but these errors were encountered: