Dashes in jinja templates

Jinja2

Jinja2 Problem Overview


Found some of these in jinja files:

</extension>
{%- else -%}
<extension name="blabla">

And also

{% if freeswitch_dispatcher -%}
<extension name="hold_unhold">

See the dashes ? Any idea what it's for ?

Jinja2 Solutions


Solution 1 - Jinja2

Turns out that + and - are there for whitespace control purpose.

> You can manually disable the lstrip_blocks behavior by putting a plus sign (+) at the start of a block
> [...]
> You can also strip whitespace in templates by hand. If you put an minus sign (-) to the start or end of an block (for example a for tag), a comment or variable expression you can remove the whitespaces after or before that block

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAntoView Question on Stackoverflow
Solution 1 - Jinja2AntoView Answer on Stackoverflow