Skip to content

Instantly share code, notes, and snippets.

@balupton
Last active October 13, 2015 08:18
Show Gist options
  • Save balupton/4166882 to your computer and use it in GitHub Desktop.
Save balupton/4166882 to your computer and use it in GitHub Desktop.
DocPad: Localising Dates
# Requires
moment = require('moment').lang('fr') # set locale to french
# Define Configuration
docpadConfig =
templateData:
# Format the passed date, by default format like: Thursday, November 29 2012 3:53 PM
formatDate: (date,format='LLLL') -> return moment(date).format(format)
# Export Configuration
module.exports = docpadConfig
This document was last modified at: <%= @formatDate(@document.date) %>
@mikeumus
Copy link

I'm getting this when I try it:

error: An error occured:
TypeError: undefined is not a function
    at Object.docpadConfig.templateData.formatDate

on [email protected]

@fizzvr
Copy link

fizzvr commented Apr 13, 2013

in JS

var docpadConfig,moment;
moment = require('moment');
moment.lang('es');

docpadConfig = {
  templateData: {
formatDate: function(date, format) {
  if (format == null) {
format = 'LLLL';
  }
  return moment(date).format(format);
}
  }
};
module.exports = docpadConfig;

@zenorocha
Copy link

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