helper-moment
Template helper for formatting dates with moment.js. Works with Handlebars, Lo-Dash or any template engine that supports helper functions.
Install with npm
npm i helper-moment --save
Run tests
npm test
Register the helper
This should work with any engine, here are a few examples
template
Register the helper for use with any template engine
template.helper('moment', require('helper-moment'));
assemble
To register the helper for use with assemble v0.6.x:
assemble.helper('moment', require('helper-moment'));
verb
Register the helper for use with verb:
var verb = require('verb');
verb.helper('moment', require('helper-moment'));
verb.task('default', function() {
verb.src('.verb*.md')
.pipe(verb.dest('./'));
});
handlebars
var handlebars = require('handlebars');
handlebars.registerHelper('moment', require('helper-moment'));
Lo-Dash or underscore
// as a mixin
_.mixin({moment: momentHelper});
_.template('<%= _.moment("YYYY") %>', {});
//=> '2015'
// passed on the context
_.template('<%= moment("YYYY") %>', {moment: momentHelper});
//=> '2015'
// as an import
var settings = {imports: {moment: momentHelper}};
_.template('<%= moment("YYYY") %>', {}, settings);
//=> '2015'
Example usage
With Handlebars:
With Lo-Dash or Underscore:
<%= moment("YYYY") %>
//=> 2015
With Verb (lo-dash, with special delimiters to avoid delimiter collision in markdown docs):
{%= moment('2015') %}
//=> 2015
Examples
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue
To request or contribute a helper to the github.com/helpers org, please read this contributing guide to get started.
Author
Jon Schlinkert
License
Copyright (c) 2014 Jon Schlinkert
Released under the MIT license
This file was generated by verb on December 06, 2014. To update, run npm i -g verb && verb
.