简体   繁体   中英

Readability of thymeleaf

I'm used to writing templates like this:

<div class="person">
    ${name}
</div>

This seems much more readable for me, in that I can see the variables outside of the tags themselves. Currently in thymeleaf, I would need to do:

<div class="person" th:text="${name}" />

Or:

<div class="person" th:text="${name}">
    ${name} // this text will be replaced and doesn't matter
</div>

Is there a way to enter in the variable like I have at the top?

Sure, you can use expression inlining for this.

<div class="person">
    [[${name}]]
</div>

In the documentation I linked, it does have a discussion of using expression inlining vs natural templating. I personally prefer natural templating in most cases.

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