Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Thymeleaf - custom attribute

I need to set custom attribute (data-validation-matches-message) value from messages resources.

<input data-validation-matches-message="Text from messages resources" /> 

I can receive and print messages resources value as:

<p th:text="#{user.notfound}"></p> 

But how I can set this value for a custom attribute (data-validation-matches-message)?

UPD (I use this)

<input th:attr="data-validation-matches-message=#{user.notfound}"/> 
like image 941
Pavel Avatar asked Feb 15 '14 17:02

Pavel


People also ask

How do you set a variable value in Thymeleaf?

We can use the th:with attribute to declare local variables in Thymeleaf templates. A local variable in Thymeleaf is only available for evaluation on all children inside the bounds of the HTML tag that declares it.

What is dialect in Thymeleaf?

Dialects. Thymeleaf Dialects are sets of features we can use in your templates. These features include: Processing logic specified via processors that apply to attributes in our tags (or tags themselves).

Is Thymeleaf a MVC?

1. Overview. Thymeleaf is a Java template engine for processing and creating HTML, XML, JavaScript, CSS and text. In this tutorial, we will discuss how to use Thymeleaf with Spring along with some basic use cases in the view layer of a Spring MVC application.


1 Answers

Since Thymeleaf 2.1 you can do this:

<a data-th-attr="data-groupid=${somevalue}, data-groupname=${someothervalue}">...</a> 

source

like image 196
Jaroslav Záruba Avatar answered Oct 15 '22 20:10

Jaroslav Záruba