Jethik
Jethik

Reputation: 1876

How to get date format in underscore js while rendering template?

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.

Upvotes: 2

Views: 5017

Answers (2)

lifo
lifo

Reputation: 2893

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

Upvotes: 1

Vadim Podlevsky
Vadim Podlevsky

Reputation: 179

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.

Upvotes: 2

Related Questions