简体   繁体   中英

Formatting a tag is not working with Thymeleaf

Why does this piece of code display the image before the text:

<p>
  <span>
    <img src="../assets/images/favorite.svg" height="12px"/>
  </span>
  Baked Alaskan Salmon with Asparagus
</p>

But when formatted with Thymeleaf it does not display the image:

<p th:text="@{' ' + ${recipe.name}}">
  <span>
    <img src="../assets/images/favorite.svg" height="12px"/>
  </span>
  Baked Alaskan Salmon with Asparagus
</p>

Try using Thymleaf's th:inline="text" tag to display html content inside of Thymleaf processed tags. Following code should work, i have not tested it though

<p th:inline="text">
    [[@{' ' + ${recipe.name}}]]
    <span>
        <img src="../assets/images/favorite.svg" style="height:12px"/>
    </span>
    Baked Alaskan Salmon with Asparagus
</p>

For more description on how inline tag works check out the docs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM