1. A modern Java templating language
Thymeleaf
Andre Azzolini!
Broadleaf Commerce!
FW JUG - July 2nd, 2014
2. Introduction
Who am I?!
‣ Graduated from The University of Texas at Austin (Computer Science)!
‣ Consultant at Credera!
‣ Senior Engineer at Broadleaf Commerce!
!
What is Broadleaf Commerce?!
‣ Open source Java enterprise eCommerce framework!
‣ Focus on extensibility and scalability!
‣ Based on Spring, Hibernate, Thymeleaf
3. ‣ Why use Thymeleaf?!
‣ Thymeleaf Basics!
‣ Intermediate Thymeleaf!
‣ Existing Ecosystem!
‣ Broadleaf Use Cases
Agenda
4. ‣ Not compiled —> short feedback loop!
‣ Natural templating —> closer to designers’ HTML!
‣ Modular architecture —> hooks for customization
Why use Thymeleaf?
35. ‣ Code completion for out of box processors!
‣ Content assist inside expressions!
‣ Ability to provide completion for custom processors
Eclipse IDE Plugin
36. ‣ Use Thymeleaf templates in Tiles definitions!
‣ Mix JSP and Thymeleaf templates!
‣ Optional Spring MVC 3 and Spring Web Flow 2.3
integrations
Thymeleaf + Apache Tiles 2
37. ‣ Lightweight dialect approach instead of Tiles!
‣ Uses decorators and fragments within the templates, so
there is no need for a Tiles definition file!
‣ Created by a core Thymeleaf contributor!
‣ I think it's more intuitive than the Tiles plugin
Layout Dialect (unofficial)
38. ‣ sec:authorize processor (accepts normal Spring Security
expressions like hasRole('ROLE_ADMIN'))!
‣ Grab the current authentication object in expressions:
${#authentication.name}!
Spring Security 3
39. ‣ Allows you to specify a cache attribute on a DOM
element!
‣ Caches the resulting HTML with the provided name!
‣ Doesn't require Thymeleaf to process the DOM for that
node when rendering
Cache Dialect (unofficial)
<ul cache:name="productsList" cache:ttl="60">
<li th:each="product : ${products}"
th:include="components/productBlock" />
</ul>
40. ‣ JavaScript library for natural templating!
‣ Can process th:include without executing in an
application!
‣ Provides features for evaluating conditionals while
statically prototyping
Thymol (unofficial)
42. ‣ Serve individual files in development, but a bundle in
production!
‣ Handle expiration of bundles!
‣ Dynamically modify contents of certain resources
JS / CSS Bundling
<blc:bundle name="admin.js"
files="BLC.js,
BLC-system-property.js,
blc-dates.js" />
43. ‣ Intelligent auto-generation of cache keys!
‣ Provide ability to alter a portion of the cached,
generated HTML!
‣ Invalidate cache elements when things change in the
admin
Advanced Caching Strategy
44. ‣ Allow users to modify templates through the admin
tool!
‣ Serve templates directly from the database!
‣ No need for compiling the templates like we would
have to with JSP
Database Template Resolution