-
Notifications
You must be signed in to change notification settings - Fork 8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Need example or documentation on how to use a custom render #415
Comments
I figured it out in the end, though it would be really helpful for others to get this documented for the future. I did something like this, which seems to work: type Pongo2Renderer struct { } func (p Pongo2Renderer) Instance(name string, data interface{}) render.Render { return Pongo2Renderer{} } func (p Pongo2Renderer) Render(http.ResponseWriter) error { fmt.Println("Custom renderer is working") return nil } r := gin.Default() r.HTMLRender = Pongo2Renderer{} I still need to finish it, but posting this here, in case it helps someone else. |
Could you post some response time benchmarks you get using this renderer in your application as apposed to the default one? Whenever I've used the default html/template I get response times like |
Sure, but I gotta make it work first, I just needed to figure out how to make a custom renderer the "proper" way in Gin, now I just have to make the Gin Pongo2 renderer itself. I can post updates when I have it working. |
@TheRealKira I finished that little pongo2 template library for Gin in case you want to try it out: https://github.com/robvdl/pongo2gin However, 50ms for using html/template doesn't sound right to me, it shouldn't be that slow unless either the template is very complex maybe, or maybe something isn't quite done right like templates being loaded from disk upon each request rather than cached in RAM. Anyway, for a very simple template with pongo2gin I am getting 1ms for the initial render and < 1ms for subsequent renders of the same template because templates are cached. However I believe html/template should be similar in speed, I just didn't produce any comparison benchmarks (will leave that upto you), but it somewhat surprises me that Pongo2 should be any faster. |
I am trying to use a custom renderer so I can use pongo2 as a template engine, I have found a commit that added this feature a while back:
5ea7a92#diff-703ef7478e12fbd8acd9d1af87bda71cR72
However, this feature does not appear to be documented and I can't figure out how to get my own custom render to work, I've been trying out this for a while now, but without any luck.
The question was also asked here but no reply yet:
ngerakines/ginpongo2#3
However, I am not really too keen on the ginpongo2 library either, because it:
Any help would be appreciated in how to write a custom renderer.
The text was updated successfully, but these errors were encountered: