Does anyone know of a workaround for nesting dynamic collections within each other in Webflow?

Published on
September 22, 2023

Yes, there is a workaround for nesting dynamic collections within each other in Webflow. While Webflow does not have a native feature to directly nest dynamic collections, you can achieve this by using multiple collection lists and custom code.

Here's a step-by-step guide on how to achieve this workaround:

  1. Create the parent collection: Start by creating the first dynamic collection that will act as the parent collection. This collection will contain the individual items that will be used as the basis for the nested collections.

  2. Create the child collection: Create a separate dynamic collection that will be used as the nested collection. Set up the fields and structure as needed.

  3. Add a reference field: In the child collection, add a reference field that will link each item to the respective parent item in the parent collection. This field will establish the relationship between the parent and child items.

  4. Add items to both collections: Fill in the parent collection with the desired items. For each item, add a reference to the corresponding child item in the child collection.

  5. Set up the CMS structure: On your page design, set up two Collection Lists. The first Collection List will be used to loop through the parent collection, and the second Collection List will be nested within the first one and will loop through the child collection.

  6. Customize the nested Collection List: For the nested Collection List, use custom code to filter only the items that have a reference to the current parent item. You can use JavaScript or jQuery to achieve this. Make sure to follow Webflow's guidelines for using custom code within the CMS.

  7. Display the data: Within the nested Collection List, you can now display the data from the child collection.

By following these steps, you can create a workaround to nest dynamic collections within each other in Webflow. While it requires some manual setup and custom code, it provides a solution for displaying nested data in a structured way.

Additional Tips:

  • Ensure that the number of child items per parent item is manageable to avoid performance issues.
  • Test your implementation thoroughly to ensure that the correct data is being displayed.

Example Code Snippet:

<!-- Parent Collection List --><div class="parent-collection">  <div class="parent-item" data-parent-item>    <!-- Display parent item content -->  </div>  <!-- Nested Collection List -->  <div class="nested-collection">    <div class="nested-item" data-nested-item>      <!-- Display nested item content -->    </div>  </div></div><script>document.addEventListener('DOMContentLoaded', function() {  var parentItems = document.querySelectorAll('[data-parent-item]');  parentItems.forEach(function(parentItem) {    var parentId = parentItem.getAttribute('data-parent-item');    var nestedItems = document.querySelectorAll('[data-nested-item]');    nestedItems.forEach(function(nestedItem) {      var nestedParentId = nestedItem.getAttribute('data-nested-item');      if (nestedParentId === parentId) {        nestedItem.style.display = 'block'; // Or any other custom display logic      }    });  });});</script>

Potential questions:

  1. Can you nest dynamic collections within each other in Webflow?
  2. How to create nested dynamic collections in Webflow?
  3. Is there a workaround for nesting collections in Webflow?