moj-frontend icon indicating copy to clipboard operation
moj-frontend copied to clipboard

Documentation doesn't explain how to import Nunjucks filters

Open gregtyler opened this issue 2 years ago • 0 comments

The Messages and Timeline components both depend on a mojDate filter, which is provided in the Pattern Library code. However, the documentation doesn't contain instructions on how to install that filter, or even mention that this is necessary.

We should add a documentation page explaining how to install filters, including a snippet to start with, and link to it from the two components that use the filter in a banner in the "How to use" section.

An existing snippet in a README is:

let mojFilters = require('./node_modules/@ministryofjustice/frontend/filters/all')();
mojFilters = Object.assign(mojFilters);
Object.keys(mojFilters).forEach(function (filterName) {
  nunjucksAppEnv.addFilter(filterName, mojFilters[filterName])
});

But I dare say we can clean that up a bit before publication.

This only affects production Node apps, as prototypes auto-configure filters.

gregtyler avatar Oct 23 '23 09:10 gregtyler