I'm generating my Knot's config from a Jinja2 template, and I'm having a
problem with one thing. For example, if I have a list of elements,
[e1,e2,e3,e4], and I want to generate a "groups" config for these based
on a condition, and I do:
groups {
mygroup {
{% for x in list %}
{% if condition %}
{{ x }},
{% endif %}
{% endfor %}
}
However, this results in a syntax error, because the last element ends
with a comma, and then there's a closing bracket.
I tried to insert the comma conditionally, by checking to see if it was
the last element, but this can also fail if the last element didn't
match the condition.
So I thought about this ugly hack:
groups {
mygroup {
{% for x in list %}
{% if condition %}
,{{ x }}
{% endif %}
{% endfor %}
}
Notice that I have the comma *before* each element. This results in an
opening brace, a comma, and then the other elements. My supposition is
that Knot's syntax parser is okay with this, because it just sees a null
first element. If I check this with knotc's "checkconf", it says the
syntax is okay.
Can I safely use such a config?
Regards,
Anand