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?
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.
Sign up to join this communityIf 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.)