[Drupal] How can we hide a block for empty views in Drupal 7

| | 1 min read

In your Drupal website consider that you have created a block using views to display some content.Consider a situation where there is no content in the view.In normal situation if there is no content to be displayed, an empty block will be displayed which will be very odd for a website.So in this article I am mentioning so configuration changes that need to be done so that the block wont be displayed when there is no content.

The following configuration changes have to hide a block for empty views in Drupal 7:

Open the view that has been created.

Open the Advanced options by clicking the 'Advance' link on the right side of the block view.

We have to add a contextual filter for the block by clicking on the 'Add' link near the 'contextual Filters'.

Now in the drop down list set 'For' on 'This block (override)' option so that the contextual filter is set only for the particular block.

In the filter select set it as 'Global' and check the 'Global: Null' option that displays and click on 'Apply (this display)'

Now from the options under the 'When the filter value is NOT available' label select the 'Hide view' option and click on 'Apply (this display)'.

Now check whether the block is getting displayed when the view is empty.