6

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 ;)

Nikolai Samteladze
  • 7,699
  • 6
  • 44
  • 70

2 Answers2

7

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.

Nikolai Samteladze
  • 7,699
  • 6
  • 44
  • 70
2

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.

Matty77
  • 21
  • 1