Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
184 views
in Technique[技术] by (71.8m points)

html - Thymelaf block loosing style

I have this piece of code:

<div class="col-md-3 col-sm-6 text-center">
<a href="/" class="logo logo_image">
    <span>
        <block >Plats</block>
        <span class="muellerhoff" >Bruts</span>
    </span>
    <img src="http://172.114.143.253:7080/images/logo.png" >
</a>
</div>

and I see this on the browser:

enter image description here

but when I use thymeleaf:

<div class="col-md-3 col-sm-6 text-center">
    <a href="/" class="logo logo_image">
        <th:block th:text="${@environment.getProperty('site.name1')}" />
        <span class="muellerhoff" th:text="${@environment.getProperty('site.name2')}"></span>
        <img th:src="@{/images/logo.png}" th:alt="${@environment.getProperty('site.name')}"  th:title="{@environment.getProperty('site.name')}">
    </a>
</div>

the style is lost:

enter image description here

and when I do view source I see this:

<div class="col-md-3 col-sm-6 text-center">
                            <a href="/" class="logo logo_image">
                                Plats
                                <span class="muellerhoff">Bruts</span>
                                <img th:src="@{/images/logo.png}" th:alt="${@environment.getProperty('site.name')}"  th:title="{@environment.getProperty('site.name')}">
                            </a>
                        </div>

I also tried <block th:text="${@environment.getProperty('site.name1')}" /> with the same result

question from:https://stackoverflow.com/questions/65951077/thymelaf-block-loosing-style

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Thymeleaf th:block is not the same as HTML tag <block>. If your first HTML snippet work as intended, enhancing it with Thymeleaf should look like the following...

<div class="col-md-3 col-sm-6 text-center">
<a href="/" class="logo logo_image">
    <span>
        <block th:text="${@environment.getProperty('site.name1')}">Plats</block>
        <span class="muellerhoff" th:text="${@environment.getProperty('site.name2')}">Bruts</span>
    </span>
    <img src="http://172.114.143.253:7080/images/logo.png" th:src="@{/images/logo.png}" th:alt="${@environment.getProperty('site.name')}"  th:title="{@environment.getProperty('site.name')}">
</a>
</div>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...