What's the difference between this:
{%block body %}
and that
{%block body -%}
Blocks are used for inheritance and act as placeholders and replacements at the same time. They are documented in detail in the documentation for the extends tag. Block names must consist of alphanumeric characters, and underscores. The first char can't be a digit and dashes are not permitted.
Just read something about it in the documentation, not sure if this will also apply on {% block ... %}
tags. Twig whitespace control
{% set value = 'no spaces' %} {#- No leading/trailing whitespace -#} {%- if true -%} {{- value -}} {%- endif -%} {# output 'no spaces' #}
There's also another example given which trims the whitespace in front of the variable but doesnt't do it at the end - so the effect is only on one side.
{% set value = 'no spaces' %} <li> {{- value }} </li> {# outputs '<li>no spaces </li>' #}
The above sample shows the default whitespace control modifier, and how you can use it to remove whitespace around tags. Trimming space will consume all whitespace for that side of the tag. It is possible to use whitespace trimming on one side of a tag
So I think the difference in your given exmaples is that in the first block body
there will be a whitespace after the block started. In your second example body -
there's none after the block started. Just read the documentation entry to see how it works.
EDIT
A simple example to demonstrate the example in the docu:
{% set value = 'NO space in source code after/before "value"' %} <li> {{- value -}} </li> ...
outputs in Firebug in the HTML markup:
Whereas this
{% set value = 'space in source code after "value"' %} <li> {{- value }} </li> ...
ouputs:
Notice the space between "value" and the closing </li>
in the second example. So the minus -
erases/trims a whitespace either before, after or on both sides of e.g. a variable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With