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.

Accepted answer

A Contextual filter is needed to a View received the content of the current page (Content ID from URL). Also necessary to add a Relationship (below Contextual filters) with the content, which is connected through Reference Field (A bridge to the Content entity that is referenced via field_blablabla). Then it will be possible to add the necessary fields using this Relationship. You can place this block anywhere in the page, this does not affect the result.

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.

A Contextual filter is needed to a View received the content of the current page (Content ID from URL). Also necessary to add a Relationship (below Contextual filters) with the content, which is connected through Reference Field (A bridge to the Content entity that is referenced via field_blablabla). Then it will be possible to add the necessary fields using this Relationship. You can place this block anywhere in the page, this does not affect the result.

@Enthusiast: I honestly have no idea what this has to do with my issue. Will adding a relationship somehow solve my problem?

I hope that correctly configured View, which displays real data, will not display an empty block and title.

Now it works after adding a relationship and checking the "Require this relationship" box.

Thanks for the help!

Do any of you know of any good resources for learning some of these more obscure aspects of Views? I don't think I ever would have found this solution on my own...

There are quite a few instructional videos here, and though I don't see a specific one on Views it is likely to be included in some of them, but there is probably a need for more specific help.

https://www.youtube.com/playlist?list=PLE6f8hiqhhJnLkJveoSQlpTzkD_nQ2UOI

We actually covered this during a session for beginners in the Backdrop Live (end of last week).

We regularly have Office Hours - see https://backdropcms.org/support/meetings - which is an informal drop-in for anyone to get support on Backdrop.

It is also perfectly fine to ask questions here; there are a number of volunteers who jump in to try to help with questions, and it has a benefit that your question can help others searching the forum for similar issues; many open source, and even some proprietary software use forums as a way for peers to support each other and get help from experts/vendors.