With Handlebars:
With Lo-Dash or Underscore:
<%= date("5 years ago", "YYYY") %>
//=> 2010
With Verb (lo-dash, with special delimiters to avoid delimiter collision in markdown docs):
{%= date('5 years ago', 'YYYY') %}
//=> 2010
Register the helper for use with any template engine
template.helper('date', require('helper-date'));
To register the helper for use with [assemble] v0.6.0 and greater:
assemble.helper('date', require('helper-date'));
Register the helper for use with [verb]:
var verb = require('verb');
verb.helper('date', require('helper-date'));
verb.task('default', function() {
verb.src('.verb*.md')
.pipe(verb.dest('./'));
});
var handlebars = require('handlebars');
handlebars.registerHelper('date', require('helper-date'));
Usage
// as a mixin
_.mixin({date: dateHelper});
_.template('<%= _.date("5 years ago", "YYYY") %>', {});
//=> 2010
// passed on the context
_.template('<%= date("5 years ago", "YYYY") %>', {date: dateHelper});
//=> 2010
// as an import
var settings = {imports: {date: dateHelper}};
_.template('<%= date("5 years ago", "YYYY") %>', {}, settings);
//=> 2010