Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mandrill Templates With Handlebars - How To Format Date

Mandrill has a great feature that allows one to use Handlebars in templates to customize email content. See docs here.

One of the helpers that Madnrill supports is date that can be used like {{#date}}. The default date format is d/m/Y. My question is how can I specify a different date format (e.g. yyyy)?

I need to display something like 2015 Name. I tried:

  • {{#date yyyy}} Name - displays 05/31/15 (default format and seems to erase any HTML after it).
  • {{#date 'yyyy'}} Name - displays {{#date 'yyyy'}} Name (can't be parsed).
  • {{#date yyyy}}{{/date}} Name - displays 05/31/15 Name (default format).
  • {{#date 'yyyy'}}{{/date}} Name - displays {{#date 'yyyy'}}{{/date}} Name (can't be parsed).

Appreciate you help ;)

like image 529
Nikolai Samteladze Avatar asked May 31 '15 22:05

Nikolai Samteladze


2 Answers

The issue was 2-fold:

  • You should use {{date}} instead of {{#date}}
  • You should use double quotes for formatting

The correct syntax would be {{date "Y"}}.

Mandrill also updated their docs that now provide more details on handlebars syntax.

like image 94
Nikolai Samteladze Avatar answered Sep 23 '22 23:09

Nikolai Samteladze


I would assume this may follow the original Merge Tag formatting. Have you tried this?

http://kb.mailchimp.com/merge-tags/all-the-merge-tags-cheatsheet

Use |DATE:FORMAT| to show the current date in a given format. For example, |DATE:d/m/y| where d is replaced by the day, m by the month, and y by the year. View a full reference of date options on the PHP website. This format isn't available for automation workflows.

like image 22
Matty77 Avatar answered Sep 25 '22 23:09

Matty77