gulp-nunjucks
gulp-nunjucks copied to clipboard
Template not found when I using extends in my template
This is my project tree view:
src
`-- templates
|-- _layouts
| `-- login.layout.njk
`-- pages
`-- login.njk
And the login.njk
{% extends "../_layouts/login.layout.njk" %}
{% block main_content %}
login page!
{% endblock %}
Emm. got same..

and my task..
exports.njk = function njk(){
return gulp.src(GULPCONFIG.filepath.njk, { base: GULPCONFIG.filepath.dev })
.pipe(nunjucks.compile())
.pipe(through.obj((chunk, enc, callback) => {
chunk.extname = '.html';
return callback && callback(null, chunk);
}))
.pipe(gulp.dest(GULPCONFIG.filepath.dist));
};
how to fixed it?
Duplicate https://github.com/sindresorhus/gulp-nunjucks/issues/14
Unfortunately in gulp-nunjucks is no option for relative path to templates.
The gulp-nunjucks-render has a better API and allows to specify the path from which all the templates will be resolved:
import gulpNunjucksRender from 'gulp-nunjucks-render';
export function buildTemplates() {
return src('templates/**/*.nj')
.pipe(gulpNunjucksRender({
path: 'templates/',
}))
.pipe(dest('dist/'))
;
}