如何在Thymeleaf中动态替换片段?

时间:2019-05-29 15:30:22

标签: java spring thymeleaf

在下面的示例中,我只想创建一个简单的\documentclass{article} % translate with >> pdflatex -shell-escape <file> % This file is an extract of the PGFPLOTS manual, copyright by Christian Feuersaenger. % % Feel free to use it as long as you cite the pgfplots manual properly. % % See % http://pgfplots.sourceforge.net/pgfplots.pdf % for the complete manual. % % Any required input files (for <plot table> or <plot file> or the table package) can be downloaded % at % http://www.ctan.org/tex-archive/graphics/pgf/contrib/pgfplots/doc/latex/ % and % http://www.ctan.org/tex-archive/graphics/pgf/contrib/pgfplots/doc/latex/plotdata/ \usepackage{pgfplots} \pgfplotsset{compat=newest} \pagestyle{empty} \begin{document} \begin{tikzpicture} \begin{axis}[ xbar, xmin=0, width=12cm, height=5.5cm, enlarge y limits=0.5, xlabel={\#participants}, symbolic y coords={Flat,Grouped}, ytick=data, nodes near coords, nodes near coords align={horizontal}, yticklabel style={rotate=90}, ] \addplot coordinates {(3,Flat) (7,Grouped)}; \end{axis} \end{tikzpicture} \end{document} 布局,以及main.htmlhome.html

子页面应仅包含其自己的内容主体,而不能包含页眉或页脚。

到目前为止,这是我所拥有的,但是现在我该如何动态地将about.html内容替换为所单击的页面?

container

如果我只有一页,可以用<html> <body> <div class="navbar navbar-inverse navbar-fixed-top"> <div class="container"> <div class="navbar-header"> <a class="navbar-brand" href="/home">Home</a> </div> <div class="navbar-collapse collapse"> <ul class="nav navbar-nav"> <li class="active"><a href="/about">About</a></li> </ul> </div> </div> </div> <div class="container"> <p>This should always get replaced when a link is clicked</p> <!--<div th:replace="fragments/pagename :: pagename">--> </div> </body> </html> 替换内容,但是如何动态地做到这一点?

1 个答案:

答案 0 :(得分:0)

弃用消息来自<html layout:decorate="layout">。将其重写为<html layout:decorate="~{layout}">可以修复该消息。

无论如何,thymeleaf似乎缺少此重要功能,因此使用thymeleaf-layout-dialect布局方言是唯一的方法。