go-macaron/macaron

How can we add new filters for pongo2

jjude opened this issue · 4 comments

jjude commented

I am using pongo2 renderer. It works fine. Now I want to add new filters to pongo2. Can it be done with the default middleware? Any examples?

Thanks

Hi, what "filters" do you mean?

jjude commented

Pongo2 comes with its own filters like 'slugify', 'date' etc. I want to add my own filters to it, say 'datefromstring'.

If I was importing pongo2 on my own without using the macaron renderer, then I could do with pongo2.RegisterFilter. But I am using the pongo2 renderer (m.Use(pongo2.Pongoer())). In this case, how to get an instance of pongo2 so that I can call RegisterFilter on it?

One possibility is to have additional option (like templateFunc) in macaron.RenderOptions. Another is to expose a pongo2 instance with which we could register new filters. Funcs is available for regular golang renderer. Same should be available for pongo2 too.

jjude commented

Got it. Thank you.