Skip to content
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

Does Nunjucks actually work with metalsmith-layouts? #62

Closed
micahgodbolt opened this issue Dec 10, 2015 · 8 comments
Closed

Does Nunjucks actually work with metalsmith-layouts? #62

micahgodbolt opened this issue Dec 10, 2015 · 8 comments

Comments

@micahgodbolt
Copy link
Contributor

Has anyone successfully got nunjucks working with metalsmith-layouts? I'm quite interested in using them after finding out Swig was no longer being maintained, but I am unable to specify the folder for includes or extends.

There was some discussion on #43 about this same issue, but it was closed without giving any examples.

@micahgodbolt
Copy link
Contributor Author

Ok! Here we go. I finally found a working solution. It just takes some external settings like so:

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

@ismay
Copy link
Member

ismay commented Dec 11, 2015

Cool, thanks for sharing. So does this work without issue? Because I've worked with nunjucks, but I remember the whole process being very fiddly.

@micahgodbolt
Copy link
Contributor Author

@ismay yes, this allows @extends and @imports to work from the specified directory

@ismay
Copy link
Member

ismay commented Dec 12, 2015

That's good to know, I'll add it to the documentation

@ismay ismay mentioned this issue Dec 13, 2015
5 tasks
@aeichepdx
Copy link

I know this is closed, but I wanted to add a quick piece of information for anyone who might be googling for help. If you need to provide separate template and partial directories, you can pass an array to the nunjucks.configure call, like so:

var nunjucks = require('nunjucks');
nunjucks.configure(['./_layouts','./_partials'], {watch: false});

This is useful if you're running into confusing "unknown path" errors like I was, when the template very obviously existed.

node build
{ [Template render error: (unknown path)
  Error: template not found: /home/user/metalsmith_build/_partials/head.html] name: 'Template render error' }

@doodzik
Copy link
Contributor

doodzik commented Jul 7, 2016

@aeichepdx Thanks for adding this bit of info.

@Andersos
Copy link

I'm trying to get Nunjucks to work with Metalsmith but where do I put this code:

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

@slavafomin
Copy link

I've written a small article on how to make Nunjucks to work with Metalsmith.

In it, I'm using in-place plugin instead of layouts, but still, I hope it could save you some time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants