テンプレートの優先順。
ginのテンプレートの機能で以下のようにテンプレートを読む設定する。
router := gin.Default() router.LoadHTMLGlob("templates/*/*.tmpl")
こうすればtemplates/なんとか
の[なんとか]が自由になる。
templates/shop/index.tmpl
templates/aho/index.tmpl
の2つ同じファイル名、ただし親フォルダが違う。
呼ぶ側はこんな感じ。c
は*gin.Context
だ。
c.HTML(http.StatusOK, "index.tmpl", gin.H{ "title": "shop", "body": shopsResponse, })
これでやると、templates/shop/index.tmpl
の方が呼ばれた。
おそらくアルファベット順でshopとahoだとaよりもsの方が後だが、
s開始のshopが呼ばれたのは、後からロードされたのが上書きしたから?
試しに、sよりもtの方が後なのでtemplates/tra/index.tmpl
とテキトーに作った。
そうすると、templates/shop/index.tmpl
ではなく、templates/tra/index.tmpl
が優先されてた。
しかし、明示的に同じファイルがある時の指定方法はどうやるのかしら?