github.com/aarzilli/tools@v0.0.0-20151123112009-0d27094f75e0/net/http/tplx/tpl_demo2.go (about) 1 package tplx 2 3 import "net/http" 4 5 type GBEntry struct { 6 Author string 7 Content string 8 } 9 10 const c_tpl_gbentry = ` 11 {{range .}} 12 - <b>{{.Author}}</b> wrote: 13 {{.Content}} <br> 14 {{end}} 15 ` 16 17 func templatesDemo2(w http.ResponseWriter, r *http.Request, m map[string]interface{}) { 18 19 gbe1 := GBEntry{ 20 Content: "It crawls into a man's bowels ...", 21 Author: "John Dos Passos", 22 } 23 gbe2 := GBEntry{ 24 Content: "Praised be the man ...", 25 Author: "T.S. Elliot", 26 } 27 vGbe := []GBEntry{gbe1, gbe2} 28 29 myTemplateAdder, myTplExec := FuncTplBuilder(w, r) 30 31 myTemplateAdder("n_html_title", "What authors think", "") // no dyn data 32 myTemplateAdder("n_cont_0", "Header <i>{{.}}</i><br><br>", "Deep thought:") 33 myTemplateAdder("n_cont_0", PrefixLff+"reloaded_template", "dyn data for file") 34 myTemplateAdder("n_cont_1", c_tpl_gbentry, vGbe) 35 myTemplateAdder("n_cont_2", "<br>end of thoughts", "") 36 37 myTplExec(w, r) 38 39 }