1.4.3 • Published 5 years ago

nunjucks-date-filter-locale v1.4.3

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

nunjucks-date-filter-locale

NPM version

Date filter for nunjucks using momentjs date format functions including locale support.

This date filter is a fork of [nunjucks-date](https://github.com/techmsi/nunjucks-date).

Installation

npm nunjucks-date-filter-locale --save

Config

// Import the plugin
var nunjucksDate = require("nunjucks-date-filter-locale");

// Define a custom default date format. Any valid format works.
// The date format defaults to "YYYY"
// http://momentjs.com/docs/#/displaying/format/
nunjucksDate.setDefaultFormat("MMMM Do YYYY, h:mm:ss a");

// Define a custom locale.
nunjucksDate.setLocale('de_DE');

// Define a custom timezone.
nunjucksDate.setTimezone('Europe/Berlin');

// Initialize your Nunjucks enironment
var env = new nunjucks.Environment();

Using default name : 'date'

// Pass the environment to `install()`
nunjucksDate.install(env);

Using custom name

// Pass the environment & a custom filter name
nunjucksDate.install(env, "yourFilterName");

The above is eqivalent to

env.addFilter("date", require("nunjucks-date-filter-locale"));

Usage

Simply format a date:

{% set today = now | date("YYYY-MM-DD") %}

Calculate a date:

{% set tomorrow = now | date("YYYY-MM-DD","add",1,"days") %}