This seems like a very basic question, but I can't seem to find any info in the docs or forum.

I have a view that potentially may have no results. I want to insert this view as a block in a layout, but I only want the title to appear if the view actually has results. 

It seems that if I set the "Block title type" to either "Default" or "Custom", the  title (i.e. the view title or the custom title defined in the block, respectively) always appears, regardless of whether the view has results or not. 

Is there any way to change this behavior? I'd be fine with having "Default" give the view title, but only if the view actually has results.

Comments

How are you generating the View?

There are a few ways to do it... but it depends on how you generate your View.

Are you using Contextual Filters?

You could use the "no results" option and add the title there, rather than using the "title" of the view... 

It seems that if I set the "Block title type" to either "Default" or "Custom", the  title (i.e. the view title or the custom title defined in the block, respectively) always appears, regardless of whether the view has results or not. 

Hmm... this is not the behavior I'm seeing.

  1. I created a View block that displays the titles of Content Type Post. Nothing unique or special about this

 

2. I place this block in the Default layout with "Default" title

 

 

3. When I visit any page, IF I have posts the view shows the title:

4. But if I delete ALL Posts (forcing an empty View) I get this:

 

I wonder if perhaps your view has something in the Header field (like a Text Area)? If so, be sure that you unclick "Display even if view has no result".

 

Here are some more details about my setup. Yes, I am using a contextual filter.

Specifically, I have several content types that have an entity reference field meant to hold references to content that is related to that node. I want to be able to display teasers of those related nodes as a grid. 

Here are some screen shots of my configuration:

 

 

My desired result is that in a case like this, the two headers at the bottom of the last screen shot should not appear (the "Gallery views" views block suffers from the same problem -- it involves a contextual filter but not entity references).

Is this related to the contextual filter somehow? I'm still quite confused by the details of how contextual filters work.

Of course, I could just display the contents of the entity reference field directly. In fact, I already do that for some content types where I want the "related content" to be in a sidebar, and it works beautifully. But in this case, I'd like it to be below the main content and laid out as a grid, and I'm not sure how to do that easily through "Manage Displays". If there is some way to do that, then that would obviously solve my problem.