Drupal 8 - How to hide a view block if content is empty

April 10, 2020

Introduction

I have created a view, with some filters and content fields. I will show it under user profile. You might want to show under whatever path. The problem is when the content is empty, only title gets displayed.

Lets see how to tackle this issue

Hide the View block if content is empty

There are two ways to hide the block:

1. Hide complete view

  • In your view edit page, goto Advanced section.
  • See the last option Hide block if the view output is empty
  • Check it
  • Save the view And, thats it.

2. Hide block, alternate

  • In block settings, Uncheck the box which says show title.
  • Goto view edit page
  • In middle col, there is a setting to add Header text
  • You can add an HTML there.
  • Put your title there, and you can use header tags
  • So, header becomes part of your content.
  • Save the view

Alternate Solutions, add custom text

  • Goto view edit page
  • See section: NO RESULTS BEHAVIOR
  • You can an Unfiltered Text, and show some message. Example: Content is not available.

See our old post, If you want to show your view only to owner user only


Similar Posts

Latest Posts