Add an expression dialect to thymeleaf to access groovy's collate

Easy way to add collate for separting lists into rows with a certain size

class Groovy {
    List<List> collate(List list, Integer columns) {
        return list.collate(columns)

class GroovyDialect extends AbstractDialect implements IExpressionEnhancingDialect {

    Map<String, Object> getAdditionalExpressionObjects(IProcessingContext processingContext) {
        return [ groovy: new Groovy() ]

    String getPrefix() {
        return "groovy"

Add dialects to TemplateEngine (code based approach), see additionalDialects in XML:

def templateEngine = new TemplateEngine().with{
    // ...
    setAdditionalDialects([new GroovyDialect()] as Set<IDialect>)
    return it

Use in template:

<div th:each="row : ${#groovy.collate(entries, 4)}" class="row-fluid">
    <ul class="thumbnails">
        <li th:each="entry : ${row}" class="span3">
            <div class="thumbnail">...</div>