Partials take styling class for section as param

This commit is contained in:
2025-09-05 11:39:14 +02:00
parent 13fe19abda
commit 3e4a4636fa
5 changed files with 30 additions and 7 deletions

20
main.go
View File

@ -98,8 +98,26 @@ func NewServer() *Server {
SonBirthDate: getEnv("SON_BIRTH_DATE", "2022-01-01"),
}
// Template Funcs
funcs := template.FuncMap{
"dict": func(values ...interface{}) (map[string]interface{}, error) {
if len(values)%2 != 0 {
return nil, fmt.Errorf("dict expects even number of args")
}
m := make(map[string]interface{}, len(values)/2)
for i := 0; i < len(values); i += 2 {
k, ok := values[i].(string)
if !ok {
return nil, fmt.Errorf("dict keys must be strings")
}
m[k] = values[i+1]
}
return m, nil
},
}
// Parse templates with error handling
templates, err := template.ParseGlob("templates/*.html")
templates, err := template.New("").Funcs(funcs).ParseGlob("templates/*.html")
if err != nil {
log.Fatalf("Failed to parse templates: %v", err)
}

View File

@ -110,7 +110,7 @@
</div>
</section>
{{template "benefits" .}}
{{template "benefits" (dict "Page" . "SectionClass" "section--light") }}
<section id="windows10-eol" class="section windows-eol">
<div class="container">
@ -322,7 +322,7 @@
</div>
</section>
{{template "linux_features" .}}
{{template "linux_features" (dict "Page" . "SectionClass" "section--light-green") }}
<section class="section cta">
<div class="container">

View File

@ -72,7 +72,7 @@
</div>
</section>
{{template "benefits" .}}
{{template "benefits" (dict "Page" . "SectionClass" "section--light-green") }}
<section class="section section--light distros">
<div class="container">
@ -113,7 +113,7 @@
</div>
</section>
{{template "linux_features" .}}
{{template "linux_features" (dict "Page" . "SectionClass" "section--light-green") }}
<section class="section cta">
<div class="container">

View File

@ -1,5 +1,8 @@
{{define "benefits"}}
<section id="voordelen" class="section {{if eq .CurrentPage "linux"}}section--light-green{{else}}section--light{{end}} benefits">
{{/* Pass SectionClass via dict: template "benefits" (dict "Page" . "SectionClass" "section--light") */}}
{{ $sectionClass := "section--light" }}
{{ with index . "SectionClass" }}{{ $sectionClass = . }}{{ end }}
<section id="voordelen" class="section {{$sectionClass}} benefits">
<div class="container">
<h2><a href="/linux">Waarom Linux kiezen?</a></h2>
<div class="benefits-grid">

View File

@ -1,5 +1,7 @@
{{define "linux_features"}}
<section class="section section--light-green linux-features">
{{ $sectionClass := "section--light-green" }}
{{ with index . "SectionClass" }}{{ $sectionClass = . }}{{ end }}
<section class="section {{$sectionClass}} linux-features">
<div class="container">
<h2><a href="/linux">Linux in actie</a></h2>
<p class="section-subtitle">Zie hoe Linux eruitziet en werkt in de praktijk</p>