str_replace in Twig
Solution 1:
Use this to replace |
with -
and replace ,
width .
:
{{age|replace({'|': "-", "," : "."})}}
Example input 31|60,
comes out as 31-60.
Solution 2:
To replace a string which is stored in twig variables:
{% 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 }) }}