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.
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.
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.
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?
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]
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
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
Sorry. Correction. This is where there should be the heading: hidden link
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.
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.
Okay I understand, glad that's working now.
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]
My issue is resolved now. Thank you!