Hi, I have set up a content template for a custom post type and I have some questions fields, up to 10. But for each post, the number of questions can be different. I am displaying the questions and answers in a divi toggle module but if a post has less than 10 questions, it displays an empty toggle. I would like the toggle to not show if there is no more questions. I have tried with a view but it's not working either. It shows nothing or a message that the field/view is empty but I would like the toggle simply not to show.
I hope it's clear enough, thanks in advance!
Hi, there's not really a good way to set up conditionals at the module level in Divi Builder. Our conditional HTML feature works best in a Text or Code module. One way to handle this is to create your design first without any conditionals, then preview it on the front-end. Copy the generated markup from the browser inspector and paste it into a Text module in the Divi Builder. Replace the static information with Types or Views shortcodes, and wrap each toggle block with conditional HTML statements as needed. Then delete the Divi Builder Toggle modules.
Hi, could you explain how to set up the conditional so that the field is not displayed if empty (if put in a text module) because I've read this https://toolset.com/documentation/user-guides/conditional-html-output-in-views/ and this https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-fields-and-other-elements-for-emptynon-empty-values/ but I don't understand how to apply it to my case.
I want to check if the field is empty, and if yes, don't display it. All I can get is "no value" or an empty text module (if the background is transparent it's fine but in my case it's grey so I get a grey line :/).
Thanks!
All I can get is "no value" or an empty text module (if the background is transparent it's fine but in my case it's grey so I get a grey line :/).
It sounds like you're saying the background of the text module is grey, so even if no content is included in the text module you see a grey line. If I understand you correctly, there is no way to turn off the text module with a conditional. So instead, you must hide the content inside the text module. Instead of using a grey background on the text module, use a background on an element inside the conditional, like a div element:
[wpv-conditional if="( $(something) ne '' )"]
<div style="background:#999;">
...All the other text module content goes here...
</div>
[/wpv-conditional]