DocPad: Localising Dates
-
Install Moment via
npm install --save moment
-
Add it and a template helper to your docpad configuration file
-
Use the template helper in your app
Install Moment via npm install --save moment
Add it and a template helper to your docpad configuration file
Use the template helper in your app
# 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) %> |
moment = require('moment').lang('fr')
doesn't seem to work but :
moment = require('moment')
moment.lang('fr')
works perfectly
To works fine is necessary the follow update in docpad.coffe
# Requires
moment = require('moment')
moment.lang('fr') # set locale to french
I'm getting this when I try it:
error: An error occured:
TypeError: undefined is not a function
at Object.docpadConfig.templateData.formatDate
on DocPad@6.30.3
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;
You can also use @brockfanning's docpad plugin: https://npmjs.org/package/docpad-plugin-moment
doesn't seem to work but :
works perfectly: http://momentjs.com/docs/#/i18n/loading-into-nodejs/