Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the current year from freemarker template

I have use the ${.now} to get the current time stamp inside the freemarker templates, but I want to know how can I get only the year?

like image 726
Anna Avatar asked May 22 '17 12:05

Anna


People also ask

How do I get the current date in FreeMarker?

If you cannot update you'll have to pass a the current date into the data model, e.g. as part of your root hashmap (see freemarker.org/docs/pgui_quickstart_createdatamodel.html and freemarker.org/docs/pgui_quickstart_merge.html for the details, if you don't already know those things).

What is the use of FreeMarker template?

FreeMarker is a template engine, written in Java, and maintained by the Apache Foundation. We can use the FreeMarker Template Language, also known as FTL, to generate many text-based formats like web pages, email, or XML files.

How do I comment in FreeMarker template?

Comments: <#-- and --> Comments are similar to HTML comments, but they are delimited by <#-- and -->. Comments will be ignored by FreeMarker, and will not be written to the output.

What is eval in FreeMarker?

eval. This built-in evaluates a string as an FTL expression. For example "1+2"? eval returns the number 3. (To render a template that's stored in a string, use the interpret built-in instead.)


1 Answers

Like ${.now?string('yyyy')}. (Note that this will return a string, which is what you want if you only want to print it. If by any chance you need a number, so that you can do arithmetic with it, then it's .now?string('yyyy')?number.)

like image 57
ddekany Avatar answered Oct 17 '22 05:10

ddekany