Sry for little information, templateName is passed from my controllers with a constant (like "templates/home.html"), so there is no problem with that. In template.new(), what do i pass ?
On Saturday, March 25, 2017 at 10:17:23 PM UTC+5:30, Yves Junqueira wrote: > > Your ParseFiles call has a "templateName" argument in it. The ParseFiles > function only takes file paths, not template names. > > And templates.New takes a template name, not a file path. > > Hope this helps. > > On Sat, Mar 25, 2017 at 9:14 AM, priyank pulumati <pulumati...@gmail.com > <javascript:>> wrote: > >> hello, >> im building a go web app and facing an issue with Executing templates >> with custom functions >> >> func CustomTemplateExecute(res http.ResponseWriter, req *http.Request, >> templateName string, data map[string]interface{}) { >> // Append common templates and data structs and execute template >> var funcMap = template.FuncMap{ >> "humanSize": humanSize, >> } >> t, _ := template.New("").Funcs(funcMap).ParseFiles(templates.BASE, >> templates.NOTIFICATIONS, templates.TICKER, templateName) >> if len(data) == 0 { >> data = make(map[string]interface{}) >> data["user"], _ = store.GetUser(context.Get(req, "userid").(string)) >> data["isadmin"] = store.IsAdmin(context.Get(req, "userid").(string)) >> } else { >> data["user"], _ = store.GetUser(context.Get(req, "userid").(string)) >> data["isadmin"] = store.IsAdmin(context.Get(req, "userid").(string)) >> } >> t.Execute(res, data) >> } >> >> func humanSize() string { >> return "Hello" >> } >> >> I get template is empty error, i have tried giving a name to template.new >> and its the same error. >> Any help is appreciated, thank you ! >> >> -- >> You received this message because you are subscribed to the Google Groups >> "golang-nuts" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to golang-nuts...@googlegroups.com <javascript:>. >> For more options, visit https://groups.google.com/d/optout. >> > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.