Skip to content

Instantly share code, notes, and snippets.

@stephentcannon
Created August 20, 2012 23:17
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save stephentcannon/3409103 to your computer and use it in GitHub Desktop.
Save stephentcannon/3409103 to your computer and use it in GitHub Desktop.
Moment.js handlebars helper
// format an ISO date using Moment.js
// http://momentjs.com/
// moment syntax example: moment(Date("2011-07-18T15:50:52")).format("MMMM YYYY")
// usage: {{dateFormat creation_date format="MMMM YYYY"}}
Handlebars.registerHelper('dateFormat', function(context, block) {
if (window.moment) {
var f = block.hash.format || "MMM DD, YYYY hh:mm:ss A";
return moment(context).format(f); //had to remove Date(context)
}else{
return context; // moment plugin not available. return data as is.
};
});
@mylastore
Copy link

I get this error: window is not defined

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment