cancel
Showing results for 
Search instead for 
Did you mean: 

Freemarker + current date

simon
Champ in-the-making
Champ in-the-making
Hi there,

I'm building a Freemarker template with the whole folder structure to have an  administrative overview of our Alfresco system. I need the current date in the following expression:

<#assign modifiedToday=""><#if "2006.05.08" == childnode.properties.modified?string("yyyy.MM.dd")>
…do something…
</#if>

Freemarker is a templating language so there is no such thing as "today". Is there some exposed variable in Alfresco I could use?
4 REPLIES 4

kevinr
Star Contributor
Star Contributor
I also noticed this strange lack of a Date object in FreeMarker and added it to the Alfresco templating data-model. So the current date (as a new Date() Java object) can be accessed in a template as the "date" object in the root of the model. For example:

<#assign datetimeformat="EEE, dd MMM yyyy HH:mm:ss zzz">
${date?string(datetimeformat)}

Hope this helps,

Kevin

simon
Champ in-the-making
Champ in-the-making
Perfect, this is exactly what I needed! Thanks Kevin.

stk137
Champ in-the-making
Champ in-the-making
does this date get created on each call within a template or just once?
It looks like it's just once as all my times are the same.

I am trying to debug a long running custom view template and see which queries are taking how long.  I was printing the time including milliseconds before and after each, but there are all identical

How can I get accomplish this?

thx


I also noticed this strange lack of a Date object in FreeMarker and added it to the Alfresco templating data-model. So the current date (as a new Date() Java object) can be accessed in a template as the "date" object in the root of the model. For example:

<#assign datetimeformat="EEE, dd MMM yyyy HH:mm:ss zzz">
${date?string(datetimeformat)}

Hope this helps,

Kevin

kevinr
Star Contributor
Star Contributor
A new Date() object is created at the start of each template execution, it is not dynamically generated each time you use it on the page.

To add a dynamic Date object, you can configure in a custom class that does what you want:
http://wiki.alfresco.com/wiki/Template_Guide#Custom_Root_Objects

Thanks,

Kevin