str reemplazar en Ramita
Quiero hacer un simple str_replace en mi plantilla twig. Soy nuevo en twig y probablemente necesito agregar un nuevo filtro o sth como ese o usar existente. ¿Cómo puedo hacer esto? ¿Dónde puedo encontrar la lista de filtros disponibles?
37
4 answers
Para reemplazar una cadena que se almacena en variables twig:
{% set twig_content_variable= 'Testing to replace content'%}
{% set replace_value_var= 'Testing' %}
{% set replace_with_value_var = 'Testing complete' %}
{{ twig_content_variable|replace({ (replace_value_var): replace_with_value_var }) }}
38
Author: M Khalid Junaid,
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
2015-09-29 21:01:09
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
2015-09-29 21:01:09
Hay un filtro de reemplazo ver documentación
30
Author: umpirsky,
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-21 08:58:27
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-21 08:58:27
Use esto para reemplazar |
con -
y reemplazar ,
ancho .
:
{{age|replace({'|': "-", "," : "."})}}
Ejemplo de entrada 31|60,
sale como 31-60.
29
Author: websky,
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
2015-09-29 21:10:53
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
2015-09-29 21:10:53
También, esto podría ser útil para deshacerse de los caracteres del lenguaje (utf-8)...
{{some_string|replace({'ć':'c','č':'c','š':'s','ž':'z','đ':'d','Ć':'C','Č':'C','Š':'S','Ž':'Z','Đ':'D'})}}
7
Author: Denis Solakovic,
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
2015-10-09 12:45:14
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
2015-10-09 12:45:14