flosch / pongo2

Django-syntax like template-engine for Go
https://www.schlachter.tech/pongo2
MIT License
2.88k stars 270 forks source link

Feature request: Specify argument names while calling macro #260

Open iredmail opened 3 years ago

iredmail commented 3 years ago

Let's say we have a macro like this:

{% macro greetings(to, from=name, name2="guest") %} ... {% endmacro %}

Currently we can only call it like this (copied from template_tests/macro.tpl):

{{ greetings() }}
{{ greetings(10) }}
{{ greetings("john") }}
{{ greetings("john", "michelle") }}
{{ greetings("john", "michelle", "johann") }}

It should be more useful to call it with argument names, especially when the macro has more arguments:

{{ greetings(to="john") }}
{{ greetings("john", from="michelle") }}
{{ greetings("john", name2="michelle", from="johann") }}

We try to organize some reusable HTML/CSS code lines to a macro, and it accepts multiple arguments. But currently the macro is not suitable for this task because hard to remember all arguments while calling the macro.

vblinden commented 1 year ago

Hello @flosch, is there any update on this? Or can you point me in the right direction to start working on this?