I would like to generate the following output with the j2cli:
// before
function (arg1,
arg2,
arg3)
// after
I tried the following template:
// before
function ({% for param in ['arg1', 'arg2', 'arg3'] -%}
{{param}}{{"," if not loop.last else ")"}}
{% endfor %}
// after
But it produces always an additional empty line at the end:
// before
function (arg1,
arg2,
arg3)
// after
When I try this template:
// before
function ({% for param in ['arg1', 'arg2', 'arg3'] -%}
{{param}}{{"," if not loop.last else ")"}}
{% endfor -%}
// after
The comment gets indented.
// before
function (arg1,
arg2,
arg3)
// after
This one
// before
function ({% for param in ['arg1', 'arg2', 'arg3'] %}
{{param}}{{"," if not loop.last else ")"}}
{%- endfor %}
// after
removes the empty line at the end but produces one at the beginning.
// before
function (
arg1,
arg2,
arg3)
// after
And this one
// before
function ({% for param in ['arg1', 'arg2', 'arg3'] -%}
{{param}}{{"," if not loop.last else ")"}}
{%- endfor %}
// after
removes all whitespace.
// before
function (arg1,arg2,arg3)
// after
How to format the function correctly?