pongo2 icon indicating copy to clipboard operation
pongo2 copied to clipboard

Include statement doesn't work inside for loop

Open wesselvanderlinden opened this issue 1 year ago • 0 comments

When I use include statements outside of for loops, they seem to work, but when I move the include statement over to the for loop it errors out.

My code:

    <form>
        {% for fieldName in object.Fields %}
            {% include "field/text.django" with name="TEST" %}
        {% endfor %}
    </form>

And the error I get:

failed to render: [Error (where: checkForValidIdentifiers)] context-key '' (value: '<schema.Type Value>') is not a valid identifier

If I move the include statement like below, I get no error and the 'field/text.django' template gets rendered correctly:

    <form>
         {% include "field/text.django" with name="TEST" %}

        {% for fieldName in object.Fields %}

        {% endfor %}
    </form>

Are include statements not supposed to work inside for loops, or am I doing something wrong?

For reference, this is the contents of field/text.django:

<label for="{{ name }}">
    {{ name }}
    <input type="text" id="{{ name }}" name="{{ name }}" />
</label>

wesselvanderlinden avatar Sep 26 '23 07:09 wesselvanderlinden