drupal|April 10, 2020|1 min read

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

TL;DR

Configure the view's 'No results behavior' or use the 'Hide block if the view output is empty' setting to prevent empty view blocks from rendering.

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

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

Related Posts

Drupal 8 - How to Theme Form and its Fields with reordering fields

Drupal 8 - How to Theme Form and its Fields with reordering fields

Introduction In this post, we will see how to theme form and its fields…

Drupal 8 - How to create a Page with admin access and create its menu entry in Reports (No Coding)

Drupal 8 - How to create a Page with admin access and create its menu entry in Reports (No Coding)

Introduction I needed a report page, where I wanted to have some information…

Drupal: How to detect country and redirect to country specific website by using Cloudflare

Drupal: How to detect country and redirect to country specific website by using Cloudflare

Introduction Assume you have a drupal website and using cloudflare. You are…

Drupal - How to rename column of a content type

Drupal - How to rename column of a content type

Introduction You already have a content type with one or more fields in it…

Drupal 8 - How to hide help link About text formats and text format guidelines

Drupal 8 - How to hide help link About text formats and text format guidelines

Problem In drupal textarea field, it was always a pain to see the two links…

Drupal 8 Smart Image Style - Handle aspect ratio for small and long images

Drupal 8 Smart Image Style - Handle aspect ratio for small and long images

Problem Statement I’ve been using image styles, and heavily used “Scale and crop…

Latest Posts

Claude Code Skills — Build a Better Engineering Workflow with AI-Powered Code Reviews, Security Scans, and More

Claude Code Skills — Build a Better Engineering Workflow with AI-Powered Code Reviews, Security Scans, and More

Most developers use Claude Code like a search engine — ask a question, get an…

Building an AI Voicebot for Visitor Check-In — A Practical Guide to Handling the Messy Parts

Building an AI Voicebot for Visitor Check-In — A Practical Guide to Handling the Messy Parts

Every office lobby has the same problem: a visitor walks in, nobody’s at the…

Server Security Best Practices — Complete Hardening Guide for Production Systems

Server Security Best Practices — Complete Hardening Guide for Production Systems

Every breach post-mortem tells the same story: an unpatched service, a…

Staff Engineer Study Plan for MAANG Interviews — The Complete 12-Week Roadmap

Staff Engineer Study Plan for MAANG Interviews — The Complete 12-Week Roadmap

If you’re a Senior Engineer (L5) preparing for Staff (L6+) roles at MAANG…

XSS and CSRF Explained — The Complete Guide with Real Attack Examples and Defenses

XSS and CSRF Explained — The Complete Guide with Real Attack Examples and Defenses

XSS and CSRF have been in the OWASP Top 10 for over a decade. They’re among the…

OWASP Top 10 (2021) — Every Vulnerability Explained with Code

OWASP Top 10 (2021) — Every Vulnerability Explained with Code

The OWASP Top 10 is the industry standard for web application security risks. If…