[Django]-Can we pass array/list to template content blocks in django? python

2๐Ÿ‘

You need to pass a list in a variable or object, you can do it like this:

{% include "partials/pickUp-Order-Form.html" with form="list test".split %}

or you can create the variable first and then pass it to the include tag:

{% with "list test" as list %}
    {% include "partials/pickUp-Order-Form.html" with form=list.split %}
{% endwith %}
๐Ÿ‘คNazkter

-2๐Ÿ‘

The include django template tag can be used for loading and rendering HTML templates where the context/data that was passed to the original template gets passed.

You can find documentation about this functionality in the built-ins section.

So if you would like to include a template, of which original view that renders the template has the following context dict: {'word': 'Bird', 'power_level': 9001} you can render it inside another template with: {% include "word_template.html" with word="Not a Bird" power_level="470" %}, which will in turn change the values to the desired ones.

To answer the question:

It should work

Taking into consideration you include a template which will not use the list type as something else.

๐Ÿ‘คDavid Lipnik

Leave a comment