Variables in nested golang templates
<p>I want to define variables inside of a golang template, instead of in a binary so that there is no need to recompile.  </p>

<p>In Go, I set some vars:</p>

<pre><code>var animals = map[string]string{
    "spirit_animal":    "cat",
    "spirit_predator":  "dog",
}
</code></pre>

<p>I execute the template with this: <code>t.ExecuteTemplate(w, "main", variables)</code> which passes these vars to the template.  </p>

<p>Now I would like to take these vars from go and into the "main" template.</p>

<pre><code>{{$spirit_animal:="cat"}} {{$spirit_animal}}
</code></pre>

<p>And I call sub-templates like this:</p>

<pre><code>{{ template "navbar" . }}
</code></pre>

<p>The problem is that nested templates (sub templates) do not appear to have access to any variables.  </p>

<p>From the <a href="https://golang.org/pkg/text/template/#pkg-overview" rel="noreferrer">documentation</a>, "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.  </p>

<p>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?</p>