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.
By Jaypan on
In Drupal 8, it appears that using the ! (exclamation mark) placeholder with the t() function has been removed.
I have a variable that contains HTML:
<span class="fullname_wrapper"><span class="first_name">John</span> <span class="last_name">Hancock</span> <span class="account_name_wrapper">(@JohnH)</span></span>
I want to keep this HTML, as it will be styled specifically wherever it appears on the site.
In Drupal 7, I was able to do this:
t('Your name is !name', array('!name' => $name));
In which $name contains the HTML shown above. However, in Drupal 8, this doesn't work since the exclamation mark pass-through placeholder has been removed.
I tried this:
t('Your name is :name', array(':name' => $name));
But of course, the HTML is escaped.
The @ mark also escapes the HTML.
Does anyone know how HTML can be passed through the t() function in D8?
Comments
Link to answer on the repost on Drupal Answers
https://drupal.stackexchange.com/a/220900/19480
https://www.martin.postma.website/