You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if v, ok := a.(*template.Template); ok {
c.w.WriteHeader(c.status)
err := v.Execute(c.w)
if err != nil {
c.logger.Println("Could not write the response", err)
}
return 1 // todo?
}
The text was updated successfully, but these errors were encountered:
xeoncross
changed the title
How do you send HTML?
Support html/template
Feb 1, 2018
Not having used templates myself, I did not even think about it. Do you have anything to propose? Are templates cached? If we add a field as *template.Template to handler, or left it to user? Templates can be passed with dependency injections.
Well, the nice thing would be for the system to handle *template.Template for you. Since Templates almost always need params, having a SetHtml() seems wasteful as you would 1) have to manually load and compile templates in each handler (compare with automatic JSON responses) and 2) you would end up passing large byte streams/slices around multiple times causing wasted GC and allocs.
My prosed type-check solution up above assumes the templates have no params from the handler/context which isn't normal:
It looks like there is no option for returning HTML/templates.
Can we add a check for this?
The work around is to manually set the header and return
[]byte
.Possible Solution:
The text was updated successfully, but these errors were encountered: