SpringBootのthymeleaf、layoutDialectを使用してlayoutを共有化したいのですが、上手く動作しません。
恐らくlayoutファイルへアクセスする為のコードが間違っているものと考えられます。
templates/signout/signout.html → アクセス → templates/layouts/layout
コード:layout:decorate="~{layouts/layout}"
詳細
templates/layouts/layoutに共有コードを記載しています。
このlayoutを layout:decorate="~{layouts/layout}" で templates/signout/signout.html に使用しようと考えているのですが、恐らくディレクトリ階層上の問題でアクセスできません。
具体的には、layoutに記載しているBootstrapの設定が反映されません。
layout内にreplaceしてあるheaderやfooterファイルの文字列は反映されます。
試した事
templates/signout/signout.html から templates/layouts/layoutへ layout:decorate="~{layouts/layout}" ではアクセスできない様なので layout:decorate="~{../layouts/layout}" と変えてみたのですが上手くいきませんでした、、
下記ソースコードです。
templates/layouts/layout内にreplaceしているheaderやfooterは別途用意しています。
templates/layouts/layout
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<head>
<title layout:title-pattern="$CONTENT_TITLE | $LAYOUT_TITLE">Thymeleaf de layout</title>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.4/css/all.css">
<link rel="stylesheet" media="all" th:href="@{/css/style.css}" />
</head>
<body>
<div layout:replace="~{layouts/header::header}"></div>
<div id="content" class="clearfix">
<div class="container-fluid ">
<div layout:fragment="content" th:remove="tag"></div>
</div>
</div>
<!-- <div layout:fragment="content" th:remove="tag"></div> -->
<div layout:replace="~{layouts/footer::footer}"></div>
<!-- scripts -->
<script src="webjars/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous">
</script>
<link rel="stylesheet" href="webjars/bootstrap/4.3.1/css/bootstrap.min.css"/>
<script src="webjars/bootstrap/4.3.1/js/bootstrap.min.js"></script>
</body>
</html>
templates/signout/signout.html
<!DOCTYPE html>
<html
xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorate="~{layouts/layout}">
<body layout:fragment="content">
<main>
<div class="container col-md-9 col-md-offset-3">
<h2>テスト</h2>
</div>
</main>
</body>
</html>