I'm using the Twig templating system as well as the Timber plugin within WordPress and one thing the Timber pages say about escaping is that:
By default, Timber does not escape the output of standard tags (i.e. {{ post.field }}). If you want to enable autoescape behavior simply add these lines to functions.php:
https://timber.github.io/docs/guides/escapers/
Does this mean if I turn this on I won't need to do any escaping whatsoever? Not for the html body, attributes, url's etc?
Additionally, if I don't turn this on, does this mean it is recommended do do something like this:
<nav role="navigation">
<ul class="main-nav">
{% for item in menu.get_items %}
<li class="{{ fn('esc_attr', (item.classes | join(' '))) }}">
<a href="{{ item.get_link|e('esc_url') }}">{{ item.title|e }}</a>
{% if item.children %}
<ul class="sub-menu">
{% for child in item.children %}
<li class="sub-menu-item">
<a href="{{ child.get_link|e('esc_url') }}">{{ child.title|e }}</a>
</li>
{% endfor %}
</ul>
{% endif %}
</li>
{% endfor %}
</ul>
</nav>
I used fn('esc_attr', item.classes)
to utilise the WordPress escaper esc_attr
as it doesn't appear like Timber has an escape for attributes and the Twig version wasn't added to 1.9, but it appears Timber is on 1.35.2.
Are there any disadvantages to auto-escaping? Doesn't seem to me like there would be unless you were planning on not escaping everything? ...and you can always utilise |raw
if you don't want something escaped I would assume?