npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

engine-nunjucks

v0.2.0

Published

More comprehensive consolidate-style engine support for nunjucks. Should work with express, assemble, verb, generate, update, and any other app that follows consolidate conventions.

Readme

engine-nunjucks NPM version NPM downloads Build Status

More comprehensive consolidate-style engine support for nunjucks. Should work with express, assemble, verb, generate, update, and any other app that follows consolidate conventions.

Install

Install with npm:

$ npm install --save engine-nunjucks

Usage

var engine = require('engine-nunjucks');

API

.configure

Initialize Nunjucks with the given options and default settings from engine-nunjucks.

Params

  • options {String}

Example

engine.configure([options]);

.addGlobal

Add a global value that will be available to all templates. Note: this will overwrite any existing global called name. Returns env (the nunjucks instance) for further method chaining.

Params

  • name {String}
  • returns {any} value

Example

engine.addGlobal(name, value);

.addExtension

Add a custom nunjucks extension. Also called "tags". This exposes the parser API and allows you to do anything you want with the template.

Params

  • name {String}: The name of the extension to add
  • returns {Function} fn: function

Example

env.addExtension(name, fn);

.compile

Asynchronously compile the given string, with the given options and callback. If no callback is passed, .compileSync is called with the given arguments.

Params

  • str {Object}: The string to compile
  • options {Object|Function}: Options object to pass to nunjucks or callback function
  • cb {Function}: Callback function
  • returns {undefined}

Example

engine.compile('foo  bar', function(err, fn) {
  console.log(fn({title: 'AAA'})); //=> 'foo AAA bar'
  console.log(fn({title: 'BBB'})); //=> 'foo BBB bar'
  console.log(fn({title: 'CCC'})); //=> 'foo CCC bar'
});

.compileSync

Synchronously compile the given string with options.

Params

  • str {Object}: The string to compile
  • options {Object}: Options object to pass to nunjucks
  • returns {Function}: returns the compiled function

Example

var fn = engine.compileSync('foo  bar');
console.log(fn({title: 'AAA'})); //=> 'foo AAA bar'
console.log(fn({title: 'BBB'})); //=> 'foo BBB bar'
console.log(fn({title: 'CCC'})); //=> 'foo CCC bar'

.render

Asynchronously render the given template string with locals and callback.

Params

  • str {String}
  • options {Object|Function}: or callback function
  • callback {Function}

Example

var locals = {name: 'engine-nunjucks'};
engine.render('abc engine-nunjucks xyz', locals, function(err, html) {
 console.log(html);
 //=> '[foo:bar]'
})

.renderString

Asynchronously or synchronously render the given str with locals and optional callback.

Params

  • str {Object|Function}: The string to render or compiled function.
  • locals {Object}
  • returns {String}: Rendered string.

Example

var engine = require('engine-nunjucks');
engine.renderString('engine-nunjucks', {name: 'engine-nunjucks'}, function(err, str) {
  console.log(str);
  //=> 'engine-nunjucks'
});
// or
var str = engine.renderString('engine-nunjucks', {name: 'engine-nunjucks'});
console.log(str);
//=> 'engine-nunjucks'

.renderSync

Synchronously render the given str (or compiled function) with locals.

Params

  • str {String|Function}: The string to render or compiled function.
  • locals {Object}
  • returns {String}: Rendered string.

Example

var engine = require('engine-nunjucks');
engine.renderSync('engine-nunjucks', {name: 'engine-nunjucks'});
//=> 'engine-nunjucks'

.renderFile

Render the contents of the file at the given filepath, with locals and optional callback.

Params

  • filepath {String}
  • options {Object|Function}: or callback function
  • cb {Function}

.addFilter

Register custom filter name with the given fn. nunjucks filters are technically similar to handlebars helpers, but they're used differently in templates. This method is also aliased as .filter.

Params

  • name {String}: Filter name
  • fn {Function}: Filter function.

Example

engine.addFilter('foo', function(str) {
  // do stuff to `str`
  return str;
});

.addFilters

Register multiple template filters. Also aliased as .filters.

Params

  • filters {Object|Array}: Object, array of objects, or glob patterns.

Example

engine.addFilters({
  foo: function() {},
  bar: function() {},
  baz: function() {}
});

.addAsyncFilter

Register an async filter function. Also aliased as .asyncFilter.

Params

  • name {String}: Filter name.
  • fn {Function}: Filter function

Example

engine.addAsyncFilter('upper', function(str, next) {
  next(null, str.toUpperCase());
});

.addAsyncFilters

Register multiple async template filters. Also aliased as .asyncFilters.

Params

  • filters {Object|Array}: Object, array of objects, or glob patterns.

Example

engine.addAsyncFilters({
  foo: function() {},
  bar: function() {},
  baz: function() {}
});

.getFilter

Get a previously registered filter.

Params

  • name {String}: Filter name
  • returns {Function}: Returns the registered filter function.

Example

var fn = engine.getFilter('foo');

.getAsyncFilter

Get a previously registered async filter.

Params

  • name {String}: Filter name
  • returns {Function}: Returns the registered filter function.

Example

var fn = engine.getAsyncFilter('foo');

Default options

These are the actual default options used. These can be overridden with custom values on any of the methods.

var defaults = {
  ext: '.html',
  name: 'nunjucks',
  base: 'templates',
  throwOnUndefined: true,
  autoescape: false,
  watch: false
};

About

Related projects

  • assemble: Get the rocks out of your socks! Assemble makes you fast at creating web projects… more | homepage
  • generate: Command line tool and developer framework for scaffolding out new GitHub projects. Generate offers the… more | homepage
  • update: Be scalable! Update is a new, open source developer framework and CLI for automating updates… more | homepage
  • verb: Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used… more | homepage

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Building docs

(This document was generated by verb-generate-readme (a verb generator), please don't edit the readme directly. Any changes to the readme must be made in .verb.md.)

To generate the readme and API documentation with verb:

$ npm install -g verb verb-generate-readme && verb

Running tests

Install dev dependencies:

$ npm install -d && npm test

Author

Jon Schlinkert

License

Copyright © 2016, Jon Schlinkert. Released under the MIT license.


This file was generated by verb, v0.9.0, on July 27, 2016.