liveBook · Manning

Th:text

As explained in Spring in Action, Sixth Edition

th:text is a Thymeleaf namespace attribute that replaces an element's body with the value of an expression.

th:text is a Thymeleaf namespace attribute that replaces an element’s body with an expression’s value. The ${} expression reads a request attribute, such as message, while the surrounding HTML provides a placeholder during template design. section 2.1.3

Render a message

Use <p th:text="${message}">placeholder message</p>. When Thymeleaf renders the template, the paragraph body becomes the value of the message request attribute. section 2.1.3

<h3>Designate your wrap:</h3>
<div th:each="ingredient : ${wrap}">
  <input th:field="*{ingredients}" type="checkbox" 
         th:value="${ingredient.id}"/>
  <span th:text="${ingredient.name}">INGREDIENT</span><br/>
</div>

In a taco-design form, th:text replaces the INGREDIENT placeholder with each ingredient’s name while th:each renders the surrounding element for every item. section 2.1.3

How Spring in Action, Sixth Edition covers it

How deep it goes
Defines body replacement and ${} request-attribute lookup, with a property-access example inside collection rendering.
Examples
Shows a message paragraph and ingredient-name spans in a taco-design form.
What it assumes
Builds from HTML templates and request attributes populated from model data before view rendering.
What you can do after
Apply it via Thymeleaf to replace HTML placeholders with request-attribute values.
How it connects
Connects Thymeleaf templates with HTML elements, servlet request attributes, expressions, and collection iteration.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring in Action, Sixth Edition. The section links point to the parts of the book it draws on.