✨Discover storytelling in the AI age with Pixar's Matthew Luhn at Sanity Connect, May 8th—register now

Is it possible to mix explicitly defined list items with a dynamic documentList in the structure builder?

3 replies
Last updated: Jun 10, 2021
In the structure builder, is it possible to mix explicitly defined list items with a dynamic documentList?For example showing a list item at the top of the pane for categories, and then the list of all posts below, instead of having to drill down one more level to "all posts".
Jun 7, 2021, 1:57 AM
Wondering the same thing!
Jun 9, 2021, 11:45 AM
User I think it may be possible by defining the structure asynchronously , and then manually creating an array of items with the categories one first, and the document items following, instead of using a built in structure builder method. Here's something similar I did:
  .title('Child Pages by Parent')
  .child(() =>
    documentStore.listenQuery(`*[_type == "page" && defined(content.main.parent._ref)]{'parent': content.main.parent->}`).pipe(
      map(allParentPages => {
        // Filter array for unique values since the query will return
        // the parents of all children so there will be duplicates
        const parents = allParentPages
            (parentDocument, index, array) =>
                .map(mapObj => mapObj._id)
                .indexOf(parentDocument._id) === index,
          .map(uniqueParents => uniqueParents.parent);

        const parentListItems = parents.map(parent =>
                .filter('content.main.parent._ref == $parentId')
                  parentId: parent._id,

        return S.list()
          .title('Child Pages by Parent')
Jun 9, 2021, 4:57 PM
Thank You Nic! Will give this a try 👍
Jun 10, 2021, 7:57 AM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?