Search code examples
javascriptjqueryhtmlspring-bootthymeleaf

anchor text url is not showing as link in th:text thymleaf


I converted some text to show as link, it's coming correctly from back-end but at UI it not shows as link. I am using thymelaf to render the text inside p tag. Please find the code below:

html file:

 <div class="column" style="margin-left: auto; margin-right: auto; float: none;" th:each="pre:${prrMap}"> 
     <div class="prerequisite" align="center">
              <label class="prerequisite" th:text="${pre.key}"></label>
              <p class="prerequisite" id="prerequisite" th:text=${pre.value}></p>
      </div>
  </div>

th:text=${pre.value} contains the String having anchor text.

Example: ${pre.value} = "prerequisite: Tesing data {a href="https://ecom-test-data.index.html"}test link {/a} link created data but not showing as link"

I cannot include anchor text tag here, so used {} = <>, It shows as it is at front-end.

Excepted output: prerequisite: Testing data test link link created data but not showing as link


Solution

  • Use th:utext (instead of th:text) if you wish to output unescaped html.