How to test for a List in Jinja2?

MFB picture MFB · Aug 14, 2012 · Viewed 31.1k times · Source

As far as I can see, there is no way to test if an object is a List instance in Jinja2.

Is that correct and has anyone implemented a custom test/extension in Jinja2?

Answer

insider picture insider · Sep 12, 2016

I did it like this:

{% if var is iterable and (var is not string and var is not mapping) %}

You can find a list of all jinja tests here.