sindresorhus / gulp-nunjucks

Precompile Nunjucks templates
MIT License
152 stars 20 forks source link

Template not found when I using extends in my template #28

Open hungtcs opened 6 years ago

hungtcs commented 6 years ago

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 %}
dmoosocool commented 6 years ago

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?

alkorlos commented 3 years ago

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

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

slavafomin commented 2 years ago

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