Skip to content
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

Pongo2 as templating engine #1023

Open
petkostas opened this issue Sep 10, 2022 · 8 comments
Open

Pongo2 as templating engine #1023

petkostas opened this issue Sep 10, 2022 · 8 comments

Comments

@petkostas
Copy link
Contributor

The template engine used by Hoverfly looks stale (Raymond) I would propose to consider porting Pongo2 as the template engine of choice.
Pongo2 is active, has similar approach to Raymond but includes more features

@tommysitu
Copy link
Member

Thanks @petkostas. Will take a look this week.

@tommysitu
Copy link
Member

looks promising. As long as it supports handlebars for backward compatibility, and is fast (because hoverfly is used for load testing in many places), it's worth a try.

@petkostas
Copy link
Contributor Author

petkostas commented Sep 15, 2022

This should cover the requirements for Hoverfly
https://pkg.go.dev/github.com/flosch/pongo2#RegisterFilter
Might require a few changes here and there, but we could also introduce helper methods, allowing the registration of extensions (tags/filters, etc) dynamically, without having to wait for a new release of the project.
Regarding performance, we need to check, yet I believe, as it's more maintained and adopted that should match Raymond.
In the case there are incpompatibilies, a flag could be introduced to switch template engine over the other, similar to how Django supports them

@petkostas
Copy link
Contributor Author

Also as I mentioned, I am fairly new to GO so I am not really aware of all the alternatives, if there is something else more promising feel free to drop it here, I can possibly provide some context after 10+ years of working with Jinja and Django templates.

@moikot
Copy link

moikot commented Oct 27, 2022

Hi @tommysitu I have a very weird case when JSON is a value of an attribute of some XML which in its turn a property value of a JSON e.g.

{
  "prop": "<table baz=\"{&quot;version&quot;:1}\">Foo</table>"
}

And I wonder if it's possible to access version property of the innermost JSON using current templates (Raymond) or any other future templating mechanism.

@kapishmalik
Copy link
Collaborator

kapishmalik commented Jan 4, 2023

@tommysitu someone has done benchmarking on go templates engine and it seems pongo2 is much faster than raymonds(named as handlebars in the link). You can check below github link for benchmarking results. If it seems promising, then probably, we can keep both for a while by taking the option from the user to use and then deprecate it other one after sometime.

https://github.com/SlinSo/goTemplateBenchmark#full-featured-template-engines-1
https://github.com/SlinSo/goTemplateBenchmark

@kapishmalik
Copy link
Collaborator

kapishmalik commented Jan 5, 2023

@petkostas Is there a way in pongo2 to access context in the filter functions?

Secondly, can we do a method call as {{<method name> <args1> <args2>}}. I see that method can be called via {{method(arg1,arg2)}}. I could not find these two in their documentation. These are required for backward compatibility.

@petkostas
Copy link
Contributor Author

@kapishmalik not sure for this, as I have not personally used pongo2 (but rather Django) for the first question, it should be available (context).
I will try to find some time and do some tests with it and get back

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants