Learn how to hide a block if no results are returned.
Transcript
Trainer (00:00):
When you create a block using Views, you may have a situation where no results are returned, but the block is still displayed. Let me show you. Let’s edit the view again, and make sure you are on the block display, and click on the published filter and change published status from yes to no. This means it’ll show us unpublished content, which as you can see in the previous section, we have no unpublished content. Now save the view, and we can see the latest articles block, but we can’t see any content. And the block kind of looks broken with no content inside. At this point, we have two options.
Trainer (00:41):
The first option is we can display a message, such as no articles returned. Or the second option is to hide the block totally if no results are returned. Let me show you how to hide the block. Let’s edit the view. Then click on advanced and click on the setting right down at the bottom, hide block if the view output is empty. Simply check this check box, hide block if no results/empty text. Then click on apply. Now this setting is only available for the block display. You won’t see it on the page display. Then click on save. And now we cannot see the block because no results are returned.
Trainer (01:25):
But if we edit the view, and this time we need to go to structure, Views, and edit latest articles and change the published filter back so it’s displaying published content. And if we look in the preview, we can see content again. And if we save the view then go to the front end, we can see the block again. My recommendation is to always have the hide block setting checked.