Skip to content

Instantly share code, notes, and snippets.

@IndianGuru
Created January 19, 2016 04:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IndianGuru/65908fe30dc43f69326d to your computer and use it in GitHub Desktop.
Save IndianGuru/65908fe30dc43f69326d to your computer and use it in GitHub Desktop.
Handler using the same template in different template files
func process(w http.ResponseWriter, r *http.Request) {
rand.Seed(time.Now().Unix())
var t *template.Template
if rand.Intn(10) > 5 {
t, _ = template.ParseFiles("layout.html", "red_hello.html")
} else {
t, _ = template.ParseFiles("layout.html", "blue_hello.html")
}
t.ExecuteTemplate(w, "layout", "")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment