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?
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).
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.
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.
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.)
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
.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With