web-nunjucks
v1.0.2
Published
A Nunjucks interface for DADI Web
Downloads
6
Readme
Nunjucks engine interface
This module allows Nunjucks templates to be used with DADI Web.
Installation
Add this module as a dependency:
npm install web-nunjucks
Include it in the
engines
array passed to Web:require('@dadi/web')({ engines: [ require('web-nunjucks') ] })
Configuration
The following configuration parameters can be added to the global Web config file, under engines.nunjucks
.
paths
Paths required by Nunjucks.
- Format:
Object
- Default:
{ { helpers: 'workspace/utils/helpers' } }
Partials
Filters
To use filters supply the path to your filters in the main Web configuration file:
"engines": {
"nunjucks": {
"paths": {
"filters": "workspace/filters"
}
}
}
Filters are individual JavaScript files within the specifed directory:
Example: workspace/filters/uppercase.js
module.exports = input => {
return input.toUpperCase()
}
Helpers
To use helpers supply the path to your helpers in the main Web configuration file:
"engines": {
"nunjucks": {
"paths": {
"helpers": "workspace/helpers"
}
}
}
Helpers are Nunjucks macros stored in individual files within the specifed directory, or all in a single file.
Example:
{#
Returns the full name and price of the supplied product
Usage: {{ renderProduct product }}
#}
{% macro renderProduct(product) %}
helper: {{ product.name }} - £{{ product.price }}
{% endmacro %}