user3292534
user3292534

Reputation:

How do I insert space in Jinja template for loop?

I populate textarea with

textarea.value='{%for i in range(0,3)%}{{data[i][0]}}{% endfor %}'.

But It produces string without spaces in between i so the output is like firstsecondthird. I'd like it to be first second third.

What are the ways to do it?

Upvotes: 2

Views: 15777

Answers (2)

Ahmed Amr
Ahmed Amr

Reputation: 589

You need to do it outside the calculation part:

textarea.value='{%for i in range(0,3)%}{{data[i][0]}} {% endfor %}'

Notice the space after {{data[i][0]}}

Upvotes: 6

user3292534
user3292534

Reputation:

...it can be done by {%for i in range(0,3)%}{{data[i][0]+" "}}

As per Jinja documentation:

+ Adds two objects together. Usually the objects are numbers but if both are strings or lists you can concatenate them this way.

Upvotes: 4

Related Questions