Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

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?