Skip Navigation

[Resolved] Toolset Types: hide header for empty view

This thread is resolved. Here is a description of the problem and solution.

Problem: I have a View built in a Content Template that displays on all posts in a custom post type. If the View does not display results, I would like to hide the corresponding header text in the template.

Solution: Move the header text into the view itself, and use a conditional block to hide it if the number of results found is less than 1.

This support ticket is created 3 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 6 replies, has 2 voices.

Last updated by chrisL-13 3 years, 8 months ago.

Assisted by: Christian Cox.

Author
Posts
#2009937

>>> Tell us what you are trying to do?
I am using Toolset Blocks to create a single item content template for a Toolset post type called 'Case study'.

The content template includes a view that shows a list of links (created as a custom repeatable field) assigned to the type 'Case Study'. The view lists the related links under a heading 'Further Reading'

Not every case study will have these links.

I only want the header 'Futher reading' to appear on case studies that have links.

I have figured out how to eliminate the 'No items found message'

And I have seen that there's an 'Items found' tag in the classic views editor that I could put the header tag in.

But how do I get at it when the view was created in Toolset Blocks?

Site is hidden link

cmkl

#2009945
2-insert-before.png
1-select-view-loop.png

Hello, in this case it's best to build the Header contents inside the View itself, rather than as a separate block element outside the View block's contents. When using the Block Editor to create a View, the "items found" tag from the legacy editor corresponds to the entire View Output block in the Block Editor experience. That includes the View Loop block, but it also includes any other content inside the View Output block but outside the View Loop. That other content will only appear when the View produces results. So if you want the header to only appear when items are found, you should move the Header into the View Output block, but outside the View Loop block, so it isn't repeated for each result of the View.

If you're having trouble placing the Heading block in the right location, select the View Loop block, then use the "insert before" menu item to insert contents just before the View Loop block. See the screenshots here for more information about that.

#2010077
Screen Shot 2021-04-04 at 4.19.58 PM.png
Screen Shot 2021-04-04 at 4.22.18 PM.png

Hi Christian,

Thanks for the rapid reply on a weekend. That sounds really promising and simple. I think I have followed your instructions.

The first screen shot is me putting the 'Further Reading' header within the view output block. The second screen shot is what's rendered to the browser when viewing a Case Study page that has no associated links for 'Further Reading'. I expect that the 'Further Reading' header would not appear.

When I view the page source, the heading is within the view layout <div> tag.

Is there some other setting to the view output that I'm missing? Or have you got a plan B? I can't have this header hanging around for nothing.

#2010095

May I log in and see how this is configured in wp-admin? I must be missing something. Please provide a URL where I can see the results on the front-end of the site, and I'll give you some additional feedback.

#2010133
Screen Shot 2021-04-04 at 8.58.55 PM.png

My apologies, you are correct. I ran a quick test and can confirm the behavior you described. It turns out my understanding of the view output block was not accurate. Blocks you place in the View Output block will be included in the output, regardless of whether or not results are found. There is a simple workaround to get the results you would like: add a conditional block that tests the number of results found in the View. I've added that for you and nested the Heading block inside that conditional.

The conditional I've set up tests whether or not any results are found in the View. If results are found, it will show the heading block. If no results are found, it will hide the heading block. I have attached a screenshot of that conditional configuration, for your reference. I also removed the "No further reading..." text bit from the "no items found" message, since you would prefer to show nothing. I hope that's okay. If not, here is the original text so you can easily replace it in the loop template panel:

[wpml-string context="wpv-views"]No further reading for this Impact Report Chapter[/wpml-string]

Sorry for the mixup, but there is an effective workaround and now we both better understand how the View Loop block is designed to work.

#2010703

Thanks for that. That will indeed work. Though I like your first idea better. It made so much sense. You should suggest it to your engineers and have them put it in the next release.

I appreciate Toolset's support enormously.

cmkl

#2010705

My issue is resolved now. Thank you!