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) %> |
You can also use @brockfanning's docpad plugin: https://npmjs.org/package/docpad-plugin-moment