BUGFIX: order of locals and globasl in template parsing

This commit is contained in:
Simon Martens
2024-12-03 21:43:26 +01:00
parent 5f6886a144
commit 591b637652
11 changed files with 14 additions and 17 deletions

View File

@@ -93,12 +93,13 @@ func (c *TemplateContext) Globals() map[string]string {
}
func (c *TemplateContext) Template(fsys fs.FS, funcmap *template.FuncMap) (*template.Template, error) {
t, err := readTemplates(fsys, nil, c.globals, funcmap)
// TODO: locals need to be in order: root, head, body
t, err := readTemplates(fsys, nil, c.locals, funcmap)
if err != nil {
return nil, err
}
t, err = readTemplates(fsys, t, c.locals, funcmap)
t, err = readTemplates(fsys, t, c.globals, funcmap)
if err != nil {
return nil, err
}

View File

@@ -51,7 +51,6 @@ func (r *TemplateRegistry) Load() error {
// TODO: what if there is no template in the directory above?
// What if a certain path is or should uncallable since it has no index or body?
func (r *TemplateRegistry) load() error {
// INFO: Parse setrs r.templates, which is why you need to make sure to call Parse() once
templates := make(map[string]TemplateContext)
fs.WalkDir(r.routesFS, ".", func(path string, d fs.DirEntry, err error) error {
if !d.IsDir() {

View File

@@ -1 +0,0 @@
<title>KGPZ - Ausgaben {{ .model.year }}</title>

View File

@@ -0,0 +1 @@
this is the menu

View File

@@ -13,14 +13,6 @@
<link rel="icon" href="/assets/logo/favicon.png" />
{{ end }}
{{ if (and .name .title) }}
<title>{{ .name }} - {{ .title }}</title>
{{ else if .name }}
<title>{{ .name }}</title>
{{ else if .title }}
<title>{{ .title }}</title>
{{ end }}
<link rel="stylesheet" type="text/css" href="/assets/style.css" />
<link href="/assets/css/remixicon.css" rel="stylesheet" />
@@ -35,6 +27,10 @@
</head>
<body class="w-full h-full" hx-ext="response-targets">
{{ block "_menu" . }}
<!-- Default app menu... -->
{{ end }}
{{ block "body" . }}
<!-- Default app body... -->
{{ end }}

View File

@@ -1 +1 @@
<title>KGPZ - Impressum &amp; Datenschutz</title>
<title>KGPZ &ndash; Impressum &amp; Datenschutz</title>

View File

@@ -1 +1 @@
<title>KGPZ - Geschichte &amp; Edition</title>
<title>KGPZ &ndash; Geschichte &amp; Edition</title>

1
views/routes/head.gohtml Normal file
View File

@@ -0,0 +1 @@
<title>KGPZ &ndash; Ausgaben {{ .model.Year }}</title>

View File

@@ -1 +1 @@
<title>KGPZ - Ausgabe {{ .model.Year }}&verythinsp;/&verythinsp;{{ .model.No }}</title>
<title>KGPZ &ndash; Ausgabe {{ .model.No }}&hairsp;/&hairsp;{{ .model.Year }}</title>

View File

@@ -1 +1 @@
<title>KGPZ - Kontakt</title>
<title>KGPZ &ndash; Kontakt</title>

View File

@@ -1 +1 @@
<title>KGPZ - Zitation</title>
<title>KGPZ &ndash; Zitation</title>