gulp-nunjucks-render
Render Nunjucks templates
Issues with the output should be reported on the Nunjucks issue tracker.
Install
Install with npm
npm install --save-dev gulp-nunjucks-render
Example
var gulp = ;var nunjucksRender = ; gulp;
Example with gulp data
var gulp = ;var nunjucksRender = ;var data = ; { return example: 'data loaded for ' + filerelative ;} gulp;
API
Options
Plugin accepts options object, which contain these by default:
var defaults = path: '.' ext: '.html' data: {} inheritExtension: false envOptions: watch: false manageEnv: null loaders: null;
path
- Relative path to templatesext
- Extension for compiled templates, pass null or empty string if yo don't want any extensiondata
- Data passed to templateinheritExtension
- If true, uses same extension that is used for templateenvOptions
- These are options provided for nunjucks Environment. More info here.manageEnv
- Hook for managing environment before compilation. Useful for adding custom filters, globals, etc. Example belowloaders
- If provided, uses that as first parameter to Environment constructor. Otherwise, uses providedpath
. More info here
For more info about nunjucks functionality, check https://mozilla.github.io/nunjucks/api.html and also a source code of this plugin.
Data
U can pass data as option, or you can use gulp-data like in example above.
;
For the following template
Would render
Environment
If you want to manage environment (add custom filters or globals), you can to that with manageEnv
function hook:
var { environment; environment} :
After adding that, you can use them in template like this:
{{ globalTitle }}{{ 'My important post'|slug }}
And get this result:
My global titlemy-important-post
License
MIT © Carlos G. Limardo and Kristijan Husak
Shout-outs
Sindre Sorhus who wrote the original gulp-nunjucks for precompiling Nunjucks templates. I updated his to render instead of precompile.
kristijanhusak for bug fixes and help with maintenance.