gulp-nunjucks icon indicating copy to clipboard operation
gulp-nunjucks copied to clipboard

Template not found when I using extends in my template

Open hungtcs opened this issue 7 years ago • 3 comments

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 %}

hungtcs avatar Jan 11 '18 02:01 hungtcs

Emm. got same.. image

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?

dmoosocool avatar Jun 13 '18 09:06 dmoosocool

Duplicate https://github.com/sindresorhus/gulp-nunjucks/issues/14

Unfortunately in gulp-nunjucks is no option for relative path to templates.

alkorlos avatar Oct 25 '20 03:10 alkorlos

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/'))
  ;
}

slavafomin avatar Sep 24 '21 19:09 slavafomin