Mostrar una cadena que contiene HTML en la plantilla twig
¿Cómo puedo mostrar una cadena que contiene etiquetas HTML en la plantilla twig?
Mi variable PHP contiene este html y texto:
$word = '<b> a word </b>';
Cuando hago esto en mi plantilla de ramita:
{{ word }}
Entiendo esto:
<b> a word <b>
Quiero esto en su lugar:
<b> a word </b>
¿Es posible conseguir esto fácilmente?
127
Author: Eric Leschinski, 2011-12-02
3 answers
Utilice la palabra clave raw, http://twig.sensiolabs.org/doc/api.html#escaper-extension
{{ word | raw }}
277
Author: Aurimas Ličkus,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-12-02 10:55:08
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-12-02 10:55:08
También puedes usar:
{{ word|striptags('<b>')|raw }}
De modo que solo se permitirá la etiqueta <b>
.
61
Author: s976,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-05-08 19:12:54
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-05-08 19:12:54
{{ word|striptags('<b>,<a>,<pre>')|raw }}
Si desea permitir múltiples etiquetas
19
Author: musicjerm,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-06-09 17:02:23
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-06-09 17:02:23