From 3e4a4636fab45b564748d5b0cebeb3286cf54e39 Mon Sep 17 00:00:00 2001 From: bdnugget Date: Fri, 5 Sep 2025 11:39:14 +0200 Subject: [PATCH] Partials take styling class for section as param --- main.go | 20 +++++++++++++++++++- templates/index.html | 4 ++-- templates/linux.html | 4 ++-- templates/partials/benefits.html | 5 ++++- templates/partials/linux_features.html | 4 +++- 5 files changed, 30 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index d653547..bee2213 100644 --- a/main.go +++ b/main.go @@ -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) } diff --git a/templates/index.html b/templates/index.html index 47c5d40..aa1bb60 100644 --- a/templates/index.html +++ b/templates/index.html @@ -110,7 +110,7 @@ - {{template "benefits" .}} + {{template "benefits" (dict "Page" . "SectionClass" "section--light") }}
@@ -322,7 +322,7 @@
- {{template "linux_features" .}} + {{template "linux_features" (dict "Page" . "SectionClass" "section--light-green") }}
diff --git a/templates/linux.html b/templates/linux.html index 6cd70dd..f49aebb 100644 --- a/templates/linux.html +++ b/templates/linux.html @@ -72,7 +72,7 @@
- {{template "benefits" .}} + {{template "benefits" (dict "Page" . "SectionClass" "section--light-green") }}
@@ -113,7 +113,7 @@
- {{template "linux_features" .}} + {{template "linux_features" (dict "Page" . "SectionClass" "section--light-green") }}
diff --git a/templates/partials/benefits.html b/templates/partials/benefits.html index 40b0ddc..33848cf 100644 --- a/templates/partials/benefits.html +++ b/templates/partials/benefits.html @@ -1,5 +1,8 @@ {{define "benefits"}} -
+ {{/* Pass SectionClass via dict: template "benefits" (dict "Page" . "SectionClass" "section--light") */}} + {{ $sectionClass := "section--light" }} + {{ with index . "SectionClass" }}{{ $sectionClass = . }}{{ end }} +

Waarom Linux kiezen?

diff --git a/templates/partials/linux_features.html b/templates/partials/linux_features.html index 349ff11..0da200f 100644 --- a/templates/partials/linux_features.html +++ b/templates/partials/linux_features.html @@ -1,5 +1,7 @@ {{define "linux_features"}} -
+ {{ $sectionClass := "section--light-green" }} + {{ with index . "SectionClass" }}{{ $sectionClass = . }}{{ end }} +

Linux in actie

Zie hoe Linux eruitziet en werkt in de praktijk