Without seeing your code, the best I can do is provide an example that shows your required functionality.
If I had to take a guess, I'd say the data you were passing in was a string, not a string pointer. A string cannot have a value of nil/null, only a string pointer can. Though that would yield a "", not a "null", (as demonstrated here), so I can only imagine that this is something weird you're doing in your code.
To prevent link-rot, I've duplicated the code examples below, though it's worth clicking through the links to see their output.
Required Functionality:
package main
import (
"log"
"os"
"html/template"
)
type TemplateData struct {
Email *string
}
func main() {
const temp = "<script>var email = {{.Email}};</script>
"
t := template.Must(template.New("email_template").Parse(temp))
email := "somebody@somewhere.com"
err := t.Execute(os.Stdout, TemplateData{
Email: &email,
})
if err != nil {
log.Println("executing template:", err)
}
err = t.Execute(os.Stdout, TemplateData{
Email: nil,
})
if err != nil {
log.Println("executing template:", err)
}
}
Trying to use a "null" string:
package main
import (
"log"
"os"
"html/template"
)
type TemplateData struct {
Email string
}
func main() {
const temp = "<script>var email = {{.Email}};</script>
"
t := template.Must(template.New("email_template").Parse(temp))
email := "somebody@somewhere.com"
err := t.Execute(os.Stdout, TemplateData{
Email: email,
})
if err != nil {
log.Println("executing template:", err)
}
err = t.Execute(os.Stdout, TemplateData{
})
if err != nil {
log.Println("executing template:", err)
}
}