Reputation: 155
I am trying to print a variable number of spaces stored in a variable in jinja2, but jinja is escaping the contents of the variable. So when I store   in the variable it gets expanded to   thus printing the characters   on the page instead of the spaces.
Here is my code:
{% macro show_message(parent_id,count) %}
{% set clist = get_message(post.id,parent_id) %}
{% set countr = count + 1 %}
{% set prefix = '-'*countr %}
{% set prefix2 = " "*countr %}
{% if clist is defined %}
{% for c in clist %}
{{ prefix2 }} Author: {{ get_author(c.user_id) }} <br/>
{{ prefix }}
{{ c.message }}
<br/><br/>
{{ show_message(c.id,countr) }}
{% endfor %}
{% endif %}
{% endmacro %}
Does anyone have a clue how to make this work?
Thanks :)
Upvotes: 3
Views: 3563
Reputation: 61
I tried Blender's way with
{{ " "|safe*10 }}
it'll generate 10 spaces
Upvotes: 5
Reputation: 298354
Mark it as safe with the |safe
filter to prevent auto-escaping:
{{ prefix2|safe }}
You also need to include the semicolon at the end of each entity:
{% set prefix2 = " "*countr %}
^
Upvotes: 3