2

I'm using the underscore.js templating function and have done a template like this:

<span class="msg-date"><% if (typeof(sent_date) != "undefined"){ %>
    <%= format(sent_date, 'd-m-Y') %><% } %>
</span>
<span class="msg-time"><% if (sent_date){ %><%= sent_date %><% } %></span>

As you can see I have add a format to sent_date in format of d-m-Y. But I can't get correct output.

Jethik
  • 1,860
  • 1
  • 22
  • 26

2 Answers2

2

There is no special date modifiers in underscore.js template() function. To format your date u can use any other third party lib for this or javascript Date object. For more details and options see this answer.

Community
  • 1
  • 1
Vadim Podlevsky
  • 181
  • 1
  • 9
1

format doesn't format dates in twig. It's basically the same as printf().

To format the date you want to use the date modifier:

sent_date|date('d-m-Y')

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
lifo
  • 2,791
  • 1
  • 25
  • 32
  • I apologize, I was thinking of this from a TWIG point of view. Not underscore.js. What output are you actually getting from your template? – lifo Dec 12 '12 at 13:33
  • Please give ans from underscore.js view – Jethik Dec 20 '12 at 05:33