Yaffs site version 1.1
[yaffs-website] / vendor / twig / twig / doc / tags / spaceless.rst
1 ``spaceless``
2 =============
3
4 Use the ``spaceless`` tag to remove whitespace *between HTML tags*, not
5 whitespace within HTML tags or whitespace in plain text:
6
7 .. code-block:: jinja
8
9     {% spaceless %}
10         <div>
11             <strong>foo</strong>
12         </div>
13     {% endspaceless %}
14
15     {# output will be <div><strong>foo</strong></div> #}
16
17 This tag is not meant to "optimize" the size of the generated HTML content but
18 merely to avoid extra whitespace between HTML tags to avoid browser rendering
19 quirks under some circumstances.
20
21 .. tip::
22
23     If you want to optimize the size of the generated HTML content, gzip
24     compress the output instead.
25
26 .. tip::
27
28     If you want to create a tag that actually removes all extra whitespace in
29     an HTML string, be warned that this is not as easy as it seems to be
30     (think of ``textarea`` or ``pre`` tags for instance). Using a third-party
31     library like Tidy is probably a better idea.
32
33 .. tip::
34
35     For more information on whitespace control, read the
36     :ref:`dedicated section <templates-whitespace-control>` of the documentation and learn how
37     you can also use the whitespace control modifier on your tags.