Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert an array to string using the jinja template engine?

I have an array element called "tags" and would like to convert the array of tags to strings separated by a blank space. But how do you do that in Jinja?

I have tried:

{{ tags|join }} 
like image 505
chutsu Avatar asked Oct 21 '12 22:10

chutsu


People also ask

Which method converts array to string?

JavaScript Array toString() The toString() method returns a string with array values separated by commas. The toString() method does not change the original array.

Which one among the following is Jinja delimiters in the template strings?

The default Jinja delimiters are configured as follows: {% ... %} for Statements. {{ ... }} for Expressions to print to the template output.

What is the difference between Jinja and Jinja2?

Jinja, also commonly referred to as "Jinja2" to specify the newest release version, is a Python template engine used to create HTML, XML or other markup formats that are returned to the user via an HTTP response.


1 Answers

Actually you are almost there, for join with space, just put it like this:

{{ tags|join(' ') }} 

see the jinja docs for more details

like image 181
number5 Avatar answered Oct 06 '22 01:10

number5