Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Using {% trans %}
function inside HTML attributes while twig_debug
is on causes HTML structure breaking because comments are not allowed inside HTML attributes.
Doesn't work:
<a aria-label="{% trans %}Go to page {{ key }}{% endtrans %}">{{key}}</a>
Works:
<a aria-label="{{ 'Go to page @key'|t({'@key': key}) }}">{{key}}</a>
The trans tag has extra details added with Twig Debug enabled.
Proposed resolution
No known resolution, other than not using {% trans %}
inside html attributes.
Remaining tasks
- Find a solution for the issue
User interface changes
-
API changes
-
Comments
Comment #1
lauriiiComment #2
joelpittetCan you update the example it's discussing HTML attributes. Twig Debug also used to fail when templates rendered stuff in
<option>
tags too for select tags.Isn't this that the trans tag has extra details added with Twig Debug?
Comment #14
joelpittetI see this all over core, I'm closing this as it seems to work and it's been 7 years...
A random of many examples in core:
<span>{% trans %}By {{ author }} {{ time }} ago{% endtrans %}</span>
Comment #15
jwilson3The code samples in the issue summary were missing the key point that #2 was asking for, which is that this bug affects strings inside HTML attributes.
Eg:
It is probably worth re-opening this issue so that it may be referenced from other issues, like this one: #2914733: [META] twig debug can break parts of site without giving the false impression that it is no longer an issue.
Comment #16
jwilson3