Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dashes in jinja templates

Tags:

jinja2

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 ?

like image 844
Anto Avatar asked Oct 16 '13 10:10

Anto


People also ask

How are variables in Jinja2 templates specified?

Variables. Template variables are defined by the context dictionary passed to the template. You can mess around with the variables in templates provided they are passed in by the application. Variables may have attributes or elements on them you can access too.

What is the difference between Jinja and Jinja2?

In the past it was possible to generate templates from a string with the default environment configuration by using jinja. from_string . Jinja 2 provides a Template class that can be used to do the same, but with optional additional configuration.


1 Answers

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

like image 159
Anto Avatar answered Sep 29 '22 14:09

Anto