I want to define variables inside of a golang template, instead of in a binary so that there is no need to recompile.
In Go, I set some vars:
var animals = map[string]string{
"spirit_animal": "cat",
"spirit_predator": "dog",
}
I execute the template with this: t.ExecuteTemplate(w, "main", variables)
which passes these vars to the template.
Now I would like to take these vars from go and into the "main" template.
{{$spirit_animal:="cat"}} {{$spirit_animal}}
And I call sub-templates like this:
{{ template "navbar" . }}
The problem is that nested templates (sub templates) do not appear to have access to any variables.
From the documentation, "A template invocation does not inherit variables from the point of its invocation." Reading the Documentation for "text/template", it sounds like variables may not be able to be used in nested templates.
Any suggestions on how to get these vars out of a binary and into a single text location accessible by nested templates that doesn't need to be recompiled on change?