Nuñito Calzada
Nuñito Calzada

Reputation: 2136

Thymeleaf placeholder in input type="text"

I have this input text in a

<input type="text" id="usernameId"  name="username" placeholder="User" />

I want to replace the text of the placeholder User for 1 text from the properties file, but I don't know if it is possible

<input type="text" id="usernameId"  name="username" placeholder="th:text="#{user.placeholder}""  />

Upvotes: 13

Views: 20198

Answers (2)

Abhay Chaudhary
Abhay Chaudhary

Reputation: 50

In the above answer it should be

<input type="text" id="usernameId"  name="username" th:placeholder="${user.placeholder}" />

${...} operator is for using with objects in context such as request, session and objects set in model.

#{...} operator is for message expressions..

Check thymeleaf tags list and thymeleaf doc for details

Upvotes: 1

holmis83
holmis83

Reputation: 16634

There is a specific Thymeleaf attribute for that:

<input type="text" id="usernameId"  name="username" th:placeholder="#{user.placeholder}" />

It can also be written like this:

<input type="text" id="usernameId"  name="username" th:attr="placeholder=#{user.placeholder}" />

Upvotes: 31

Related Questions