How to format date in Scala Template

3,620 views
Skip to first unread message

Thomas Vervik

unread,
May 12, 2012, 8:30:59 AM5/12/12
to play-fr...@googlegroups.com
I have a arrangment object with a date field, and wants to format the date something like this:

<div class="dateBox">
                <div class="day"> 24</div>
                <div class="month">April</div>
                <div class="year">2012</div>
            </div>

In freemarker for example you do like this:
@arrangement.date.format("dd.MM.yyyy"), how is this done in Play 2.0 Scala templates?

Play 1.x had JavaExtension where you could write your own extensions, but this isnt presents in Play 2.0 as far as I can see from the documention or by seaching the classes *JavaExtension" inside Idea

biesior

unread,
May 12, 2012, 8:58:43 AM5/12/12
to play-fr...@googlegroups.com
ellou' Thomas

Accidentally (or not) date formatting is the same :), check the sample applications ie.: computer database, view list.scala.html -
@computer.introduced or @computer.discontinued

W dniu sobota, 12 maja 2012 14:30:59 UTC+2 użytkownik Thomas Vervik napisał:
I have a arrangment object with a date field, and wants to format the date something like this:

de facto you do not need extra method for formating the code:

<div class="dateBox">
    <div class="day">@arrangement.date.format("dd")</div>
    <div class="month">@arrangement.date.format("MMMM")</div>
    <div class="year">@arrangement.date.format("yyyy")</div>
</div>

 

Play 1.x had JavaExtension where you could write your own extensions, but this isnt presents in Play 2.0 as far as I can see from the documention or by seaching the classes *JavaExtension" inside Idea

In Play 2 you can also create tags and/or "JavaExtension"-like calls, as each template is just a Scala function, 
you can easily call your methods of your classes.

 

Thomas Vervik

unread,
May 12, 2012, 9:09:01 AM5/12/12
to play-fr...@googlegroups.com
ah, huff, sorry, didnt test that before I asked.
It works like sharm now!

Thanks for your help!
Reply all
Reply to author
Forward
0 new messages