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} -->
  <ul>
    <li th:each="s : ${strList}" th:text="|${s}|"></li>
  </ul>
 
</div>

References

http://docs.spring.io/spring/docs/current/spring-framework-reference/html/expressions.html#expressions-language-ref

Categories

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

Comments

Developed and designed by Netgloo
© 2017 Netgloo