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

Referring to a previously defined variable in a GROQ query in Sanity.io

3 replies
Last updated: Feb 23, 2023
How could I refer the above
parsedSlug
?

*[_type == 'devCategory'] {
 		_id,
 		"level": 0,
 		"title": coalesce(title[$lang], title.en),
        "parsedSlug": slug.current,
 		"children": *[parent._ref == ^._id] {
 		  _id,
		  "level": 1,
          "slug": ^.parsedSlug + "/", πŸ‘ˆπŸ‘ˆ Here, I would get the above parsedSlug
 		  "title": coalesce(title[$lang], title.en),
 	  }
}
Feb 23, 2023, 10:45 AM
I believe you can use Pipeline Components , so something like:

*[_type == 'devCategory'] {
 		_id,
 		"level": 0,
 		"title": coalesce(title[$lang], title.en),
        "parsedSlug": slug.current,
 		
} | {
   ...,
   "children": *[parent._ref == ^._id] {
 		  _id,
		  "level": 1,
          "slug": parsedSlug + "/", πŸ‘ˆπŸ‘ˆ Here, I would get the above parsedSlug
 		  "title": coalesce(title[$lang], title.en),
 	  }
}
Feb 23, 2023, 12:44 PM
Work like a charm. Thank you
user G
Feb 23, 2023, 2:39 PM
awesome 😊
Feb 23, 2023, 2:40 PM

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?