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.priy...@gmail.com> 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+unsubscr...@googlegroups.com.
> 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.

Reply via email to