Jinja2 Split string by white spaces

Calling split on the string should do the trick:

"a 1".split()

my solution is tested in iPython

In [1]: from jinja2 import Template
In [2]: Template("{{s.split('-')}}").render(s='a-bad-string')
Out[2]: u"['a', 'bad', 'string']"

I had the same issue and didn't find anything useful, so I just created a custom filter :

def split_space(string):
    return string.strip().split()

Added it to the filter list (with flask):

app = Flask(__name__)

def split_space(string):
    return string.strip().split()

#some code here

if __name__ == '__main__':

    app.jinja_env.filters['split_space'] = split_space
    app.run()

And used it as such in the template :

{% if "string" in element|split_space %} ... {% endif %}