Got a content type with some text, and a video field and an image field (and some other stuff, like entity references between nodes, but not relevant for this question).

When displaying nodes for this content type, I don't want to display the image, if there is a video available.
So the image displays if the video field is empty. If a video was added to the node, the image should not display.

Can only be done by modifying the node template I assume? So I would need to copy the node.tpl.php and rename it to node--contenttype.tpl.php (with contenttype being the name of the content type)

But the PHP code in there just prints then entire $content so I cannot interfere with the displaying of the image separately.

Is there another customisation (the one producing the html for the node probably?) where I can wrap some "if" statement around the image field that check for presence of content in the video field?

2 Answers 2


You can use conditional fields module for this. https://www.drupal.org/project/conditional_fields and set the dependency for your field. See the screenshot it will help you. enter image description here


The node template is probably where you want to be doing your changes.
Just because the current template renders the $content variable (render array), doesn't mean it has to be done that way.
The template will have many other variables defined you can use, including the fields.
The easiest way I have found to see what variables and render arrays are available in a template is to install the devel module and output the value of the get_defined_vars() function.
eg (put this in the template file after installing devel).

Doing it in a preprocess function (to alter and add variables before they get to the template) is also an option.
Setting variables in here to be used in the template is usually favored as it keeps your template clean.
As an example, in the preprocess function you could set a variable for if the video is available, eg. $hasvid = true; then in your template you could have a simple if statement checking $hasvid while at the same time keeping your template free of any complex PHP that may confuse a themer who has limited PHP experience.

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.