metalsmith / layouts

A metalsmith plugin for layouts
MIT License
116 stars 49 forks source link

Nunjucks extends, file not found #43

Closed rawberg closed 9 years ago

rawberg commented 9 years ago

Having trouble getting template inheritance to work with Nunjucks. Tried putting both templates in the layouts directory and also defining partials as "layouts" but always get "file not found" error for the template being inherited.

Consolidate.js suggets this loader option, not sure how that would work in the context of metalsmith?

rawberg commented 9 years ago

turns out the path to the template being extended is relative to the the root of the project.

{% extends "layouts/master.html" %}   // works
{% extends "master.html %} // does not work

"metalsmith-layouts" {
    "engine": "nunjucks"
}
ismay commented 9 years ago

turns out the path to the template being extended is relative to the the root of the project.

Yeah the implementations differ from engine to engine.

Consolidate.js suggets this loader option, not sure how that would work in the context of metalsmith?

Basically any option that's passed to metalsmith-layouts that it doesn't recognise is passed on to consolidate. So you can use that, and you can also configure a global instance of nunjucks (var nunjucks = require('nunjucks'); and that seems to be picked up by consolidate as well (even though the requires option is the official way of configuring an engine).

micahgodbolt commented 8 years ago

Does anyone have an explanation of how to resolve this issue? I'm having the same problem with extends and haven't had any luck with any of the suggestions mentioned here.

micahgodbolt commented 8 years ago

Ah! Finally found it. The directory has to be set like this:

var nunjucks = require('nunjucks');
nunjucks.configure('./templates', {watch: false})