Thymeleaf: create a list of elements statically

The following code can be used to statically create a list of elements (numbers, strings, etc) inside a Thymeleaf view.

A list of integers:

intList = ${ {1, 2, 3, 4} }

A list of strings:

strList = ${ {'netgloo', 'web', 'design'} }

Usage example

<div th:with="strList = ${ {'netgloo', 'web', 'design'} }">

  <!-- Some code using ${strList} -->
    <li th:each="s : ${strList}" th:text="|${s}|"></li>


  • Kumar

    How to add another element when list is already declared

    • Hello Kumar, try to take a look to this answer on Stackoverflow if can help you:

      In general, as said in the above answer also, it would be better to modify the list in your controller, before it is passed to Thymeleaf. And use Thymeleaf just to render the list.


Category BootstrapCategory CoffeescriptCategory DrupalCategory GravCategory HTMLCategory JavascriptCategory JoomlaCategory jQueryCategory LaravelCategory MagentoCategory PHPCategory SharePointCategory SpringCategory ThymeleafCategory WordPressCategory Workflow


Developed and designed by Netgloo
© 2017 Netgloo