3

I'm reading "flask_bootstrap/templates/bootstrap/base.html" on GitHub, and find some block symbols strange, like {%- block ... %} or {% endblock ... -%}. Why there is "-" before or after {% or %}?

Will it make the block declaration different than the normal? I'm going to extend this file, so I'd like to know in detail.

hjpotter92
  • 78,589
  • 36
  • 144
  • 183
ping
  • 33
  • 4

1 Answers1

1

That particular feature (whitespace control) is not from the Flask server, but from Jinja2 template engine.

From the linked docs:

You can also strip whitespace in templates by hand. If you add a minus sign (-) to the start or end of a block (e.g. a For tag), a comment, or a variable expression, the whitespaces before or after that block will be removed:

{% for item in seq -%}
    {{ item }}
{%- endfor %}
hjpotter92
  • 78,589
  • 36
  • 144
  • 183
  • Thanks for the doc link, hjpotter92! I didn't find it by google. Good to know that sign (-) does have a purpose. – ping Sep 25 '16 at 17:36