4 Whether automatic escaping is enabled or not, you can mark a section of a
5 template to be escaped or not by using the ``autoescape`` tag:
10 Everything will be automatically escaped in this block
11 using the HTML strategy
14 {% autoescape 'html' %}
15 Everything will be automatically escaped in this block
16 using the HTML strategy
20 Everything will be automatically escaped in this block
21 using the js escaping strategy
24 {% autoescape false %}
25 Everything will be outputted as is in this block
30 Before Twig 1.8, the syntax was different:
35 Everything will be automatically escaped in this block
36 using the HTML strategy
39 {% autoescape false %}
40 Everything will be outputted as is in this block
43 {% autoescape true js %}
44 Everything will be automatically escaped in this block
45 using the js escaping strategy
48 When automatic escaping is enabled everything is escaped by default except for
49 values explicitly marked as safe. Those can be marked in the template by using
50 the :doc:`raw<../filters/raw>` filter:
58 Functions returning template data (like :doc:`macros<macro>` and
59 :doc:`parent<../functions/parent>`) always return safe markup.
63 Twig is smart enough to not escape an already escaped value by the
64 :doc:`escape<../filters/escape>` filter.
68 Twig does not escape static expressions:
72 {% set hello = "<strong>Hello</strong>" %}
74 {{ "<strong>world</strong>" }}
76 Will be rendered "<strong>Hello</strong> **world**".
80 The chapter :doc:`Twig for Developers<../api>` gives more information
81 about when and how automatic escaping is applied.