Thymeleaf Interactive Tutorial

Exercise 15: parameterizable fragments

This exercise introduces concepts new in Thymeleaf 2.1. See parameterizable fragment signatures section of the What's New article.

  1. Let's start with the same-template fragments from the previous exercise. We have a fragment call banner which is used three times inside the page. We are going to add two parameters to the fragment so as to change the background color and the text shown.
  2. The first parameter will be a CSS class with possible values white, red and blue. Substitute the provided value white by a fragment parameter.
  3. The second parameter will be the text shown. Substitute the provided value The Thymeleaf tutorial by a fragment parameter.
  4. Now the values for the includes must be:
    1. white and Product information
    2. red and Customer information
    3. blue and Copyright 2013
  5. You can check the proposed solution by pressing the Show solution button () above the code editor.

Welcome to the Thymeleaf Interactive Tutorial. Thymeleaf version used in this tutorial is 2.1.5.RELEASE.

This interactive tutorial has been created by the Thymeleaf Team using The Thymeleaf Template Engine and other great open source tools like:

The tutorial is gracefully hosted at the Heroku Cloud Platform

Icons used in this app, except Thymeleaf logo, are created by Mark James

You can get the source code of this tutorial at GitHub.

You can find much more documentation on Thymeleaf at the Thymeleaf website.

For any questions or help, you can use the user forum.

Source code

Static view

Generated source

Dynamic view