Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Thymeleaf placeholder in input type="text"

Tags:

html

thymeleaf

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}""  />
like image 255
Nunyet de Can Calçada Avatar asked May 05 '17 17:05

Nunyet de Can Calçada


2 Answers

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}" />
like image 191
holmis83 Avatar answered Nov 18 '22 12:11

holmis83


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

like image 1
Abhay Chaudhary Avatar answered Nov 18 '22 11:11

Abhay Chaudhary