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

How do you configure templating engines? #6

Closed
Rowno opened this issue Jul 14, 2015 · 8 comments
Closed

How do you configure templating engines? #6

Rowno opened this issue Jul 14, 2015 · 8 comments

Comments

@Rowno
Copy link

Rowno commented Jul 14, 2015

Nunjucks needs to be able to be configured to disable it's builtin watcher and set the template directory for extending. This could be solved by exposing the consolidate template engines.

See segment-boneyard/metalsmith-templates#55

@grancalavera
Copy link

I'm using nunjucks, and I'm facing the same issue. I found you can configure nunjucks and add filters globally:

nunjucks
  .configure({watch: false})
  .addFilter('stretch', function(str) {
    return str.split('').map(function(char) {
      var stretched = '', i = 0
      for (i; i < 5; i++) { stretched += char }
      return stretched
    }).join('').toLowerCase()
  })

Then you can use the filter normally in your templates:

{{ title|stretch }}

@ismay
Copy link
Member

ismay commented Jul 16, 2015

Sorry for the late reply, I've been a little busy. But yeah, as @grancalavera said, you can configure a global instance of the templating engine to solve this.

I'm doing something similar here, where I'm instantiating handlebars and passing it some partials, to be used later in metalsmith (or gulpsmith in this case). Let me know if that solves it for you!

(I'll also add this to the documentation for posterity btw, it hasn't really been properly documented.)

@Rowno
Copy link
Author

Rowno commented Jul 16, 2015

Thanks, I ended up using Swig and configuring it globally using swig.setDefaults({ cache: false });. But it's likely that not all templating engines support global config.

@ismay
Copy link
Member

ismay commented Jul 16, 2015

@Rowno Yeah that could be, I'll check it out. It needs to at least be documented, because I ran into this myself as well.

@ismay
Copy link
Member

ismay commented Jul 16, 2015

@ismay
Copy link
Member

ismay commented Jul 17, 2015

So depending on the outcome of this issue: tj/consolidate.js#203, it might indeed be a good idea to expose the consolidate.requires object.


Edit: Yeah, consolidate.requires needs to be exposed. Not all templating languages can be configured without it, as @Rowno suspected.

@micahgodbolt
Copy link
Contributor

@ismay your link of https://github.com/superwolff/cape/blob/master/gulp/util/gulpsmith.js 404s now. I'm still struggling with nunjucks and extending directory. Is there a new home for that file?

@micahgodbolt
Copy link
Contributor

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

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

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

No branches or pull requests

4 participants