0

I am a bit confused by how Go templates execute my templates. I have a base layout and I would like to pass a string variable, so my base template can execute another template based on the string variable I passed.

This works fine.

{{ template "anotherTemplate" . }}

This does not work fine.

{{ $another := "anotherTemplate" }}
{{ template $another . }}
Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Sylnois
  • 1,589
  • 6
  • 23
  • 47
  • 2
    That's simply not allowed. If you want you can do `{{ if eq $another "anotherTemplate" }} {{ template "anotherTemplate" . }} {{ end }}`.. but not much more than that. The nested templates *need* to be known at parse time. – mkopriva Nov 28 '19 at 09:34
  • I see, i will try it out – Sylnois Nov 28 '19 at 09:37

0 Answers0