0

I want to have this image not showing if the translation is empty or non existing

<img class="partners-logo" src="{{ 'page.image.path' | trans | raw }}">

So can I wrap a logic loop around it as in the following code?

{% if {{ 'page.image.path' | trans }} is not null %}
    <img class="partners-logo" src="{{ 'page.image.path' | trans | raw }}">
{% endif %}

Obviously not right? Then how should it be?

Kailas
  • 7,350
  • 3
  • 47
  • 63
Romainpetit
  • 897
  • 2
  • 11
  • 29
  • You probably only need `{% if 'page.image.path'|trans %}` although I am not sure why `'page.image.path'` is quoted in your example. – jeroen Mar 31 '16 at 14:42
  • Possible duplicate of [How to check if a translation item exists in Twig/Symfony2?](http://stackoverflow.com/questions/9638852/how-to-check-if-a-translation-item-exists-in-twig-symfony2) – Jean-Luc Barat May 07 '16 at 11:25

1 Answers1

1

You can do something like that :

{% if "page.image.path"|trans != "page.image.path" %}

This will check if the result of the translation is different from the translation key : if a translation key has no translation, filter trans returns the translation key.

alexf
  • 1,303
  • 9
  • 20