Template: calling a method on nil receiver returns nil

This template:

{{.A.F 1}}

does not cause any errors if .A is nil. See it here: Go Playground - The Go Programming Language

Since I include an argument to the pipeline (1), can this be interpreted as anything other than a method call? How can a method call succeed if there is no method to call?

This has been a source of problems in my templates. If I mistype the first key or if the key that I expect is missing from the data model, I may not find out until much later when I notice incorrect output from the template.

Take a look at (*template.Template).Option. I think the missingkey option may do what you want: Go Playground - The Go Programming Language

Edit: Fixed link

Yes, thank you.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.