Go
フレームワークのあるバージョン1.8.1
とGin
、以下のようなプロジェクト構造を使用しています
|- src/
|- views/
|- category1/
|- layout/
- header.html
- footer.html
- index.html
|- category2/
|- layout/
- header.html
- footer.html
- index.html
|- category3/
|- layout/
- header.html
- footer.html
- index.html
それぞれに、フォルダーindex.html
から同じレベルのヘッダーとフッターファイルを含める必要があります。これを行うには、以下のように書いたフォルダーlayout
に対して行いますcategory1
index.html
{{ template "views/category1/layout/header.html" .}}
<body>
<h1>Category 1</h1>
</body>
{{ template "views/category1/layout/footer.html" .}}
をGin
使用してすべてのファイルをロードしました
router.LoadHTMLGlob("views/*/*/*.html")
しかし、期待どおりに機能していません。次のエラーが発生しています。
html/template:index.html そのようなテンプレートはありません "views/category1/layout/header.html" html/template:index.html そのようなテンプレートはありません "views/category1/layout/footer.html"