I think the approach you try with nested templates is wrong. If you want .
to be defined inside a nested template, you have to supply an argument to the call to the nested template, just as you do with the ExecuteTemplate
function:
{{define "RT"}}
Status - {{.Status}}
Proto - {{.Proto}}
{{end}}
{{define "HT"}}
{{range $key, $val := .}}
{{$key}} - {{$val}}
{{end}}
{{end}}
{{define "BT"}}
{{.}}
{{end}}
{{define "MT"}}
<html>
<body>
<pre>
-- Response --
{{template "RT" .Resp}}
-- Header --
{{template "HT" .Header}}
-- Body --
{{template "BT" .Body}}
</pre>
</body>
</html>
{{end}}
{{template "MT"}}
The important part you seem to miss is that templates do not encapsulate state. When you execute a template, the engine evaluates the template for the given argument and then writes out the generated text. It does not save the argument or anything that was generated for future invocations.
Documentation
Relevant part of the documentation:
Actions
Here is the list of actions. "Arguments" and "pipelines" are evaluations of data, defined in detail below.
... {{template "name"}} The template with the specified name is executed with nil data. {{template "name" pipeline}} The template with the specified name is executed with dot set to the value of the pipeline. ...
I hope this clears up things.