Skip Navigation

[Resolved] Conditionally display Bootstrap panel button only if view is not empty

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

Problem:

I want to conditionally hide the panel if the view within it is empty.

Solution:

You just need to move those panel HTML codes into the child view, within shortcode [wpv-items-found] ... [/wpv-items-found], for example:

https://toolset.com/forums/topic/conditionally-display-bootstrap-panel-button-only-if-view-is-not-empty/#post-1129556

Relevant Documentation:

https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-attribute

This support ticket is created 6 years, 2 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 3 replies, has 2 voices.

Last updated by Luo Yang 6 years, 2 months ago.

Assisted by: Luo Yang.

Author
Posts
#1129385

Hi there,
My question is the same as https://toolset.com/forums/topic/is-conditional-output-in-accordion-possible/.
I wasn't able to answer my question from that ticket, because not all the steps were documented.

I have a Bootstrap accordion showing various views.
I want to conditionally hide the panel if the view within it is empty.

Here is the view with the panels: hidden link
For example:

<button class="accordion">Step-by-Step Photo Instructions: [wpv-post-title]</button>
<div class="panel">
  <h4>Step-by-Step Photo Instructions: [wpv-post-title]</h4>
  <p>[wpv-view name="step-photos-for-bind-offs-class"]</p>
</div>

If the view "step photos for bind-offs class" doesn't return any results, I don't want to show the panel or its button.
Can you show me how to conditionally hide the button if the view is empty?

Here is the view contained in the panel: hidden link

Thank you,
Liat

#1129556

Dear Liat,

I can get your website credentials in your previous thread:
https://toolset.com/forums/topic/help-creating-a-nested-view-of-taxonomy-terms-to-display-on-archive-page-sidebar/#post-1101839

Yes, it is possible. you just need to move those panel HTML codes into the child view, within shortcode [wpv-items-found] ... [/wpv-items-found], for example:
Edit the view "Panels for BIND-OFFS CLASS"
hidden link

in section "Loop item in Chapter View with anchor and Panels for BIND-OFFS CLASS", change the codes from:

<button class="accordion">Step-by-Step Photo Instructions: [wpv-post-title]</button>
<div class="panel">
  <h4>Step-by-Step Photo Instructions: [wpv-post-title]</h4>
  <p>[wpv-view name="step-photos-for-bind-offs-class" knitting_videos_id="[wpv-post-id]"]</p>
</div>

To:

[wpv-view name="step-photos-for-bind-offs-class" knitting_videos_id="[wpv-post-id]"]

Pass knitting_videos post ID as view's shortcode attribute "knitting_videos_id"

2) Edit the child view "Step Photos for Bind-Offs Class", in section "Loop Editor", change the code as below:

...
[wpv-items-found]
<div class="panel">
  <h4>Step-by-Step Photo Instructions: [wpv-post-title id='[wpv-attribute name="knitting_videos_id"]']</h4>
  <p>
	...
  </p>
</div>
[/wpv-items-found]
...

More help:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-attribute

#1130115

My issue is resolved now. Thank you!

#1130238

You are welcome