0

Goフレームワークのあるバージョン1.8.1Gin、以下のようなプロジェクト構造を使用しています

|- 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に対して行いますcategory1index.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"

4

0 に答える 0