From 25eaad15950558d4b2186a0db998effb814c2af5 Mon Sep 17 00:00:00 2001 From: Daniele Tonon Date: Sat, 27 May 2023 14:45:32 +0200 Subject: [PATCH] Fix kinds/types - templates mapping --- render.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/render.go b/render.go index 372b94f..3e27d7d 100644 --- a/render.go +++ b/render.go @@ -185,6 +185,17 @@ func render(w http.ResponseWriter, r *http.Request) { "eventJSON": string(eventJSON), } + // Use a mapping to expressly link the templates and share them between more kinds/types + template_mapping := make(map[string]string) + template_mapping["profile"] = "profile.html" + template_mapping["note"] = "note.html" + template_mapping["address"] = "raw.html" + + // If a mapping is not found fallback to raw + if template_mapping[typ] == "" { + template_mapping[typ] = "raw.html" + } + funcMap := template.FuncMap{ "BasicFormatting": BasicFormatting, "SanitizeString": html.EscapeString, @@ -196,7 +207,7 @@ func render(w http.ResponseWriter, r *http.Request) { ParseFS(templates, "templates/*"), ) - if err := tmpl.ExecuteTemplate(w, "note.html", params); err != nil { + if err := tmpl.ExecuteTemplate(w, template_mapping[typ], params); err != nil { log.Error().Err(err).Msg("error rendering") return }