How can we add new filters for pongo2
jjude opened this issue · 4 comments
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?
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.
In fact, you only need to give it like any other the template variables: https://sourcegraph.com/github.com/Unknwon/gowalker@5ef7245ad7005740ffc75d23a2deefab8c7cb32f/-/blob/pkg/context/context.go#L109
Got it. Thank you.