A dialect for Thymeleaf that adds Joda utility methods to Thymeleaf templates.
Minimum of Java 7 and Thymeleaf 3.0 required. For Thymeleaf 2.1, check out the 1.x releases.
Copy the JAR from one of the release bundles, placing it in the classpath of your program, or build the project from the source code here on GitHub.
Add a dependency to your project with the following co-ordinates:
- GroupId:
nz.net.ultraq.thymeleaf
- ArtifactId:
thymeleaf-joda-dialect
- Version: (as per the badges above)
Add the Joda dialect to your existing Thymeleaf template engine, eg:
Java example:
templateEngine.addDialect(new JodaDialect());
Spring XML configuration example:
<bean id="templateEngine" class="org.thymeleaf.spring3.SpringTemplateEngine">
...
<property name="additionalDialects">
<set>
<bean class="nz.net.ultraq.thymeleaf.JodaDialect"/>
</set>
</property>
</bean>
This will introduce the joda
expression object to your Thymeleaf templates,
adding 2 new utility methods you can use in your pages: createNow
, and format
.
Creates a new Joda DateTime
instance whose time is the instant at which the
method was called.
<div th:with="now=${#joda.createNow()}">...</div>
Formats a Joda DateTime
instance according to the given format string.
Documentation on the format string can be found on Joda's API pages
here,
although it's mostly compatible with the JDK date patterns that all Java devs
know already.
<div th:text="${#joda.format(myDate, 'EEEE, d MMMM yyyy')}">...</div>