So if I have a node type of Article. I have two fields on it:

  • field_image
  • field_secondary

If field_secondary is being used, I'd like for that to be shown over field_image. Can anyone help point me in the right direction how I'd go about this?

1 Answer 1


If field_secondary is also an image field, then you can check if it is empty in your Twig template:

For example, in node--article.html.twig:

{% if content.field_secondary is empty %}
  {{ content.field_image }}
{% else %}
  {{ content.field_secondary }}
  {{ content.field_image }}
{% endif %}

{{ content.without('field_image', 'field_secondary') }}

(Your actual template will have more HTML in it.)

  • Thanks so much! This looks like exactly what I need. I'm pretty new with Twig, and was thinking I'd have to write a custom helper function for all this.
    – cstls
    Oct 9, 2020 at 11:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.