私はこのチュートリアルに従っています: http://www.thymeleaf.org/doc/layouts.html (Thymeleaf Layout Dialect セクションに移動しました)。そこに例があります:
<!DOCTYPE html>
<html>
<head>
<!--/* Each token will be replaced by their respective titles in the resulting page. */-->
<title layout:title-pattern="$DECORATOR_TITLE - $CONTENT_TITLE">Task List</title>
...
</head>
<body>
<!--/* Standard layout can be mixed with Layout Dialect */-->
<div th:replace="fragments/header :: header">
...
</div>
<div class="container">
<div layout:fragment="content">
...
</div>
<div th:replace="fragments/footer :: footer">© 2014 The Static Templates</div>
</div>
</body>
</html>
th:replace
上記の例では、フッターとヘッダーはタグに置き換えられていますが、レイアウト ファイルに<head>
はタグがあります。<title>
<head>
基本的に、タグ全体を に置き換えたいと思いth:replace
ます。したがって、私は持っています:
私のレイアウトファイル:
<!DOCTYPE html>
<html>
<head th:replace="/html/components/head :: head">
</head>
<body>
<div layout:fragment="content">
</div>
...
<div th:replace="/html/components/footer :: footer" />
</body>
<html>
私のコンテンツファイル:
<!DOCTYPE html>
<html layout:decorator="/html/layouts/layout">
<head>
<title>My content title</title>
</head>
<body>
<div layout:fragment="content">
...
</div>
</body>
</html>
そして最後に /html/components/head.htm ファイル:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<head th:fragment="head">
<meta charset="utf-8" />
<title layout:title-pattern="$CONTENT_TITLE">Layout Title should be replaced by Content Title!</title>
...
</head>
<body>
</body>
</html>
内容はまぁまぁ。フッターとヘッダーはファイルから期待どおりに含まれています (置き換えられています) が、ページ タイトルは空白です!
私は得る:
<!DOCTYPE html>
<head>
<meta charset="utf-8" />
<title></title>
...
どうしたの?