html – th:href Thymleaf inserting Variable in Link Text-ThrowExceptions

Exception or error:

Hey Guys so I’m using Thymelaf in my HTML Email template. I’m creating a hyperlink that looks like this:

<a th:href="@{https://example.com/#/login?username=__${username}__}">th:utext="https://example.com/#/login?username=${username}"</a>

The first part of the link works correctly and the username is correctly resolved by the template engine, but as you can see the link text doesn’t map at all. I want the link text to be exactly like the link itself. Does anyone know how this can bed done?

How to solve:

Solved with a simple <span> tag 🙂

<a th:href="@{https://example.com/#/login?username=__${username}__}"><span th:text="'https://example.com/#/login?username='+${username}"></span></a></p>

Leave a Reply

Your email address will not be published. Required fields are marked *