Skip to content

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

Notifications You must be signed in to change notification settings

schafe-vorm-fenster/nunjucks-date-filter-locale

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%