Baseof
Baseof template & using block
entities
All templates: single, list inherit from the baseof.html
.
- Create
giraffe_site/layouts/_default/baseof.html
and definemain
andfooter
blocks.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
Top of baseof.
<hr />
{{ block "main" . }} {{ end }}
<br />
{{ block "footer" . }} This is the default baseof Footer. {{ end }}
<hr />
Bottom of baseof.
</body>
</html>
- Modify main and footer blocks in
giraffe_site/layouts/_default/single.html
{{ define "main" }}
This is the single template.
{{end}}
{{define "footer"}}
This is the single footer.
{{end}}
- Modify only main block in
giraffe_site/layouts/_default/list.html
(will use the default footer ofbaseof.html
)
{{ define "main" }}
This is the list template.
{{ end }}
- In browser the list pages are displayed something like:
Top of baseof.
---
This is the list template.
This is the default baseof Footer.
---
Bottom of baseof.
What other blocks there can be?
(title, main, footer)
Parent template (_default/baseof.html
):
<head>
<meta charset="UTF-8" />
<title>{{ block "title" . }}
{{ end }}
</title>
</head>
Child template
{{ define "title" }}
{{ .Title }} | My Travel Blog
{{ end }}
{{ define "main" }}
<article>
<h1>{{ .Title }}</h1>
{{ .Content }}
</article>
{{ end }}
{{ end }}