Cómo ocultar una sección completa en Webflow cuando una lista está vacía

Este post le enseñará cómo ocultar toda una sección cuando una lista está vacía en webflow, lo que la función es y cuándo / por qué es posible que desee ocultar toda una sección cuando una lista está vacía en su proyecto.

Añada afiliaciones a su proyecto Webflow en cuestión de minutos.

Más información

Más de 200 componentes Webflow clonables gratuitos. No es necesario registrarse.

Ver biblioteca

Añade membresías a tu proyecto React en cuestión de minutos.

Empezar

How to hide a whole section in Webflow when a list is empty

Miembros necesarios

https://www.memberstack.com/scripts/hide-element-based-on-other-elements-children

Tutorial

Clonable

https://webflow.com/made-in-webflow/website/filter-saved-cms-items

Why/Use Cases

  1. Hide empty sections that don’t serve any purpose when empty.
  2. Improve the user experience of creating custom lists.

Sometimes, depending on your users’ activity on your site, you may have certain sections without any content. To improve your users’ experience, you may want to hide any unnecessary sections and not crowd your UI.

We’re going to be looking at an example where users can favorite items on a list and based on whether they’ve favorited anything or not, show or hide the dedicated Favorites section.

How to hide an empty section on Webflow

To set this up, we’re going to use MemberScript #25 – Hide Element Based on Other Element’s Children. Follow the link to get the code you’ll need to add to your page and watch a video tutorial on how to set everything up.

Creating your list of items

First, you’ll need to create the list itself. Create the CMS collection you’ll be using to populate the list and then build it on the frontend however you like and connect it to the CMS collection.

After you’ve created and designed your list, add these attributes to it:

  • ms-code-filter-list=”x”
  • ms-code-visibility-subject=”x”

We’re using “x” as a value just to match the list with the section itself, but you can use whatever value you like (e.g. “favorites” for a Favorites section, “pinned” for a Pinned section, and so on).

Now for the container that houses the entire section that you want to disappear if the list is empty, add the following attribute:

  • ms-code-visibility-target=”x”

Making the conditional visibility work

Now that you’ve got your list and you’ve connected it to a CMS collection, all you need to do is add the MemberScript #25 custom code to your page, before the closing body tag.

This whole thing works by hiding the target (the container with the target attribute) if the subject (the list with the subject attribute) has no children elements or if they’re set to display:none.

Conclusión

That’s it, you can now go and test your disappearing section by adding and removing elements from the list it houses.

To create more disappearing sections on your page, repeat the steps above and just replace the attribute values with something representative of this new section.

If you want to use our demo project to get you started, just click the button below to add it to your Webflow site.

Our demo will help you easily filter items out of a list based on the presence of an item within its children – this works perfectly not only for CMS lists, but also static ones and lists generated by member JSON.

Llévame a los guiones

https://www.memberstack.com/scripts/hide-element-based-on-other-elements-children

ÍNDICE
Ovidiu
¿Qué es Memberstack?

Autenticación y pagos para sitios Webflow

Añada inicios de sesión, suscripciones, contenido cerrado y mucho más a su sitio Webflow: fácil y totalmente personalizable.

Más información
Empezar a construir

Pruebe Memberstack y descubra todo lo que puede crear.

Memberstack es 100% gratis hasta que estés listo para lanzarla - así que, ¿a qué estás esperando? Crea tu primera aplicación y empieza a construir hoy mismo.