I need replace field value to some text if value equal 0
in node--new_material.html.twig

{{ content.field_cena }} - it displays the value

These filter versions don't work

{{ content.field_cena|replace({'%0%': 'some text'}) }}
{{ content.field_cena|replace('0', 'some text') }}
{{ content.field_cena.0|replace({'%0%': 'some text'}) }}
{{ content.field_cena.0|replace('0', 'some text') }}

nothing is displayed.

Please tell me the solution!

Comments

wombatbuddy’s picture

Try to rename the template, replace
node--new_material.html.twig
with
node--new-material.html.twig

Also, try this code: 

{{ node.field_cena.value|replace({'0': 'some tex'}) }}
ligraf’s picture

Cool!
Thank You very much!
It really works.

Only if there are several 0 values, they all replaced, for example
26000 replaced by 26some texsome texsome texsome tex.

I found such a way out
{% if node.field_cena.value == '0' %}
   some text
{% else %}
   {{ node.field_cena.value }}
{% endif %}