There are many situations where content needs to be created automatically. The most common case is probably the dynamic generation of web pages, for which template engines are a popular choice. Some template engines take a logic-less approach, by denying or discouraging the use of logic in templates. Examples of logic-less template systems are Mustache and Handlebars, for which Java implementations are also available: and

Logic-less templates seem to polarize opinions. Proponents see them as the best way to achieve a clear separation of concerns in MVC architectures. Opponents argue that forcing the controller to do data-massaging before sending the data to the UI is actually a bad thing, because it forces the controller to be aware of the presentation logic.

I will not take a side in this debate, because I have very little experience in developing web applications. However, template engines are also useful for other purposes and I argue that there are cases, especially in non-MVC settings, where using logic in templates is legitimate. Nonetheless, putting too much logic in a template is still a bad idea.

I used recently for generating source code and I needed to add some logic to my templates. allows you to do this through the use of helpers, therefore I wrote the Helpers library, which provides a series of helpers for common use cases. Most of them are basic helpers that can be used as subexpressions in the built-in block helpers of This lets you write the template logic in a fluent way.


Given the following YAML model:

birthYear: 1997

and the following template:

{{def 'fifteenYear' (math birthYear '+' 15)}}
{{#ifb (or
        (compare (math fifteenYear '%' 4) '==' 0)
        (compare (math fifteenYear '%' 100) '!=' 0)
    (compare (math fifteenYear '%' 400) '==' 0)
Your fifteenth anniversary was in a leap year!
Your fifteenth anniversary was in a non-leap year!

The resulting text will be:

Your fifteenth anniversary was in a leap year!

If you use, you may find this library useful, so read its documentation and give it a try!