1.0.2 • Published 4 years ago

web-nunjucks v1.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

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

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.0.1

4 years ago