{{define}}
は layouts 配下のどのファイルに書かれていても最初に全て適用(定義)される- このため例えば index.html と _default/single.html で同名の
{{define}}
を書くと
template: redefinition of template "hoge"
と言われてエラーになる
- このため例えば index.html と _default/single.html で同名の
- どこからも参照されない layouts 配下のファイル(拡張子が何でも)に
{{define}}
を書いておくこともできる {{define}}
内の名前空間は{{template}}
のふたつめのパラメタ(pipeline)になるので定義されるファイルの名前空間とは無関係- SECTION1/single.html:
{{define "fuga"}}{{.Section}}{{end}}
- SECTION2/single.html:
{{template "fuga" .}}
→ SECTION2
- SECTION1/single.html:
- つまり
{{define}}
はファイルを分離しない partial のようなもので、変数のような使い方はできない- Djangoの
{% block %}
-{% extends %}
とは考え方が違う
- Djangoの
tamacjp/Hugo-define-template
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
Hugo の {{define}}-{{template}} を理解する
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published