Querying a navigation sidebar for a documentation site using a plugin in Sanity.io.

2 replies
Last updated: Apr 4, 2024
Hello. Working on a documentation site using this plugin: https://www.sanity.io/plugins/page-tree . What would a query for a navigation sidebar be? Have gotten it to work, but using reference means i have to hardcode the max depth of the tree, so i feel like a better solution would maybe be recursive. Any ideas?
*[_type == 'homePage']{
    title,
    'contentpages': *[_type == 'contentPage' && references(^._id)]{
      title
    }
  }
Apr 4, 2024, 8:32 AM
GROQ can’t recursively resolve references, unfortunately.
Apr 4, 2024, 5:12 PM
Then i'll just limit the number of levels. Thanks
Apr 4, 2024, 5:12 PM

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?