2

We have a content type that in addition to the body field it has a field for Image and another field for Video.

Both video and image are currently displayed at the top of the node, in Node > Manage Display. But if there is already a value for video field, that should be all that needs to display. Unless the video field has no value in which case, display the image field.

In other words, we want to have a condition where the image field is hidden IF there is a value for the Video field. If no data is present for video filed, display image.

Does anyone have an idea of how this can be accomplished?

2

This should work:

{% if node.field_video is not empty %}
  {{ content.field_video }}
{% else %}
  {{ content.field_image }}
{% endif %}

If the field is populated with a value, render that field. Otherwise, render the image field.

  • Thanks Kevin. Which file in the theme directory does this go into? – Progonat Jun 22 '18 at 17:49
  • Whatever node template you are working with, like node--node-type.html.twig or node--node-type--view-mode.html.twig. – Kevin Jun 22 '18 at 17:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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