Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

web-nunjucks

1.0.2 • Public • Published
DADI Web

Nunjucks engine interface

npm (scoped) JavaScript Style Guide

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 %}

Install

npm i web-nunjucks

DownloadsWeekly Downloads

51

Version

1.0.2

License

MIT

Unpacked Size

20.4 kB

Total Files

17

Last publish

Collaborators

  • avatar