When working with Webflow, you might need to hide a page section if a CMS list is empty. Here's how you can achieve this using Webflow's features:
1. Use Conditional Visibility Setting
- Add a CMS Collection List to your page layout if you haven't already.
- Select the Collection List element in your designer.
- In the Element Settings panel, locate the Conditional Visibility option.
- Set a condition to check if a certain field in your CMS item is set or empty. For instance, set visibility based on a field like "Post Title" or "Image URL" not being empty.
2. Adjust the Wrapper Element
- Wrap your CMS List in a Div Block or any container element if it's not wrapped already. This will help apply visibility settings not just to the list but its entire section.
- Select the Div Block (or wrapper) containing the CMS List.
- Apply Conditional Visibility to the wrapper as well, using the settings from the previous step.
3. Supplement with Custom Code (Optional)
- If the above steps don't fully meet your needs, a little custom code might be necessary. Use JavaScript to check if the CMS list rendered is empty and toggle the visibility of the parent container.
- Insert the code in the Page Settings under before </body> custom code section.
Summary
To hide a page section when a CMS list is empty in Webflow, ensure your CMS List and its wrapper have Conditional Visibility settings applied. Optionally use JavaScript for more complex scenarios.