view raw
Romainpetit Romainpetit - 1 year ago 32
PHP Question

How to say "if this translation is empty"

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?


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.