使用Thymeleaf替换片段div内容的现有div

时间:2018-02-07 15:21:28

标签: java html thymeleaf

我要做的是获取视图内容片段以将其内容包含到base.html布局中,但我希望它替换该div,并且只显示3个部分标签,而不是div作为父元素。

我没有收到任何错误,但是<div th:replace="${view} :: content"></div>不是<div><section>...</section><section>...</section><section>...</section></div>成为这3个标签,而是变成<section>...</section><section>...</section><section>...</section>。我希望它只是<!DOCTYPE html> <html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"> <head> ... </head> <body> <!--main menu--> <!-- Static navbar --> <header class="navbar navbar-inverse navbar-default navbar-fixed-top navbar-transparent"> ... </header> <!--end main menu--> <div th:replace="${view} :: content"></div> <footer> ... </footer> </body> </html> 。也许我误解了替换的文档,但我明白它应该用片段的内容替换div。

这是布局文件base.html:

<!DOCTYPE html>
<html lang="en"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
    <body>
        <div th:fragment="content">
          <section>
              ...
          </section>      
          <section>
              ...
          </section> 
          <section>
              ...
          </section> 
        </div>
    </body>
</html>

以下是视图文件,默认/ view.html:

   axios.post('/traveller-register', this.form.data)
   .then(function(response){
     toastr.success(response.data.status);
     setTimeout(function(){
       window.location = response.data.redirect;
     }, 6000);
   })

1 个答案:

答案 0 :(得分:1)

我明白了。

我只需要用两个模板中的th:block替换那个div。

相关问题