Skip Navigation

[Resolved] Hiding DIVI modules if Toolset field empty

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

Problem: I would like to display a Divi module conditionally based on some custom field value.

Solution: Divi's modules do not offer any conditional display integration with Toolset's custom fields. It might be possible to use shortcodes and Toolset's conditional HTML feature if the Divi modules you want to use offer a shortcode-based option instead of the builder option.

This support ticket is created 5 years, 3 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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 12 replies, has 2 voices.

Last updated by zachariahC 5 years, 3 months ago.

Assisted by: Christian Cox.

Author
Posts
#1314817

Tell us what you are trying to do? I have created a template via a DIVI library item. You can see an example here: hidden link Scroll down to the section that starts with Background and has two toggles. For some of the athletes, they don't have these 3 items and ideally I would like to hide this entire section if all three are empty but would be okay with each of these three being hidden if there is not content in that custom field, leaving the grey background there. I've tried adding a text module above and below the module I want to hide and put in conditional statements but that didn't work.

Is there any documentation that you are following? I've searched the forum, documentation, etc.

#1314969

Hi, Divi builder modules don't offer any conditional logic integration, as far as I know. Adding conditionals surrounding the elements won't have the desired effect.

One workaround approach might be to add a CSS class to the module, then use conditional HTML in a separate text module to insert CSS that shows or hides that element based on the custom field value(s). If Divi offers a shortcode-based implementation of their collapse feature, then another option would be to implement conditional HTML in a text editor where you also include the Divi module shortcodes. We have documentation for conditional HTML available here: https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

Let me know if you need additional information about conditional HTML use in a text editor.

#1314993

Hi Christian. Thanks for the response. I would like some additional information for use in a text editor. For the section above the Background section I am using conditional html to show and hide the div's that wrap each of the items. That appears to be working just fine. However I've no luck trying to use conditional statements with the [wpv-post-body]. If I add it, no matter if it is empty or has content, it stops showing up anything.

The display in question is NOT using a view but rather a DIVI library item.

The tricky part is showing and hiding the toggles.

#1315031

Can you show me exactly how you're using conditionals with the wpv-post-body shortcode, using screenshots or by copy + pasting code in your reply?

#1315571

I'm using this

[wpv-conditional if="( $(wpv-post-body]) ne '' )"]
<h3>Background</h3>
[/wpv-conditional]
[wpv-post-body]

The h3 heading never shows up, whether the wpv-post-body has content or not.

I have used something like this higher up on the page and it works really well:

[wpv-conditional if="( $(wpcf-athlete-website) ne '' )"]
<div><span style="color: #df2427;">Website:</span><br>
[/wpv-conditional][types field='athlete-website' target='_blank'][/types][wpv-conditional if="( $(wpcf-athlete-website) ne '' )"]
</div>[/wpv-conditional]

[wpv-conditional if="( $(wpcf-personal-sponsors) ne '' )"]<div>
<span style="color: #df2427;">Personal sponsors:</span><br>[/wpv-conditional]
[types field='personal-sponsors'][/types][wpv-conditional if="( $(wpcf-personal-sponsors) ne '' )"]</div>[/wpv-conditional]
[wpv-conditional if="( $(wpcf-equipment) ne '' )"]<div>
<span style="color: #df2427;">Equipment:</span>[/wpv-conditional]
[types field='equipment'][/types][wpv-conditional if="( $(wpcf-equipment) ne '' )"]</div>[/wpv-conditional]

#1315581

Okay I see, thanks. Testing for the existence of post content is tricky because of how it is stored in the database. There's some information about a custom function workaround available here in our documentation: https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-custom-functions-in-conditions/#checking-for-empty-post-content

#1315593

Hi. I tried the functions.php solution but it doesn't seem to be working either. The h3 heading isn't showing up, whether I set the conditional to '0' or '1'

[wpv-conditional if="( wpv_conditional_post_has_content() eq '1' )"]
<h3>Background</h3>
[/wpv-conditional]
[wpv-post-body]

Here is a post that should have that heading: hidden link
Here is one that should not have that heading: hidden link

#1315595

Sorry. Correction. This is where there should be the heading: hidden link

#1315613

Okay can you confirm you registered the function in Toolset > Settings > Frontend Content > Functions in conditional evaluation? If so, then I'll need to take a closer look. May I log in to your site's admin area? Please provide credentials in the private reply fields here.

#1315623

Ah. No I didn't register that function. I have and now it is working so that is good. Just need to figure out something with the two toggles... I will see what I can do on my own. I have one idea to try.

Thanks for your help.

#1315655

Okay I understand, glad that's working now.

#1315765

Thanks. While it doesn't hide the DIVI section itself, I have figured out how to hide the two toggles successfully if empty.

The toggles themselves need to go into the DIVI library. Note the ID's of the library items. Add this to the functions.php file in your child theme:

//Shortcode to show the module
function showmodule_shortcode($moduleid) {
extract(shortcode_atts(array('id' =>'*'),$moduleid));
return do_shortcode('[et_pb_section global_module="'.$id.'"][/et_pb_section]');
}
add_shortcode('showmodule', 'showmodule_shortcode');

Add a code module where you want show the toggles (or any other DIVI module)

This is the code I used. In this case I was showing the post content and two toggles in its own section. Read above around hiding/showing the post content by using a function in functions.php. I found that the two showmodule shortcodes cannot be enclosed inside a wpv-conditional shortcode:

[wpv-conditional if="( wpv_conditional_post_has_content() eq '1' )"]
<h3 class="athletebkg" style="margin-bottom: 1rem;">Background</h3>
[/wpv-conditional]
[wpv-post-body]
[wpv-conditional if="( wpv_conditional_post_has_content() eq '1' )"]
<div class="athlete-results" style="margin-top: 2rem;">
[/wpv-conditional]
[showmodule id="1024"]
[showmodule id="1026"]
[wpv-conditional if="( wpv_conditional_post_has_content() eq '1' )"]
</div>
[/wpv-conditional]

#1315767

My issue is resolved now. Thank you!