Ahhh, wait a minute, Iâm sorry, I got confused about what you were trying to accomplish. I thought you were trying to map through sections on a single page. But looking at the code again, I think youâre trying to make individual pages (using getStaticPaths()
) out of a modular content field (sections
)?
e.g. /hire/product-1
, /hire-product-2
, etc?
You can do that, but itâs a bit non-standard to use a modular content field that way. Usually, each product would instead be a standalond record in a separate âProductsâ model, then you can generate all the product pages easily with a GraphQL query like:
allProducts {
id
slug
}
If you want to keep them as blocks inside a MCF, my suggestion is to keep that âSectionsâ field limited to one type of block only (the âProductâ), and move the âHero Bannerâ into its own separate set of fields in the Hire page.
Then, in /hire/index.astro
you can read all the stuff needed just for the /hire
page. And in /hire/[slug].astro
, you can fetch the sections
and use that only to generate the products pages (like /hire/product-1
).
Right now, I think youâre getting that error because Astro is encountering the Hero Banner block, which has no slug, and itâs trying to generate a product page from that.
Essentially, youâve combined two schemas into one, and itâs confusing Astro (and me! )
Once you clean that up, you donât need to map through sections
again within each product page, because each product page IS already a post
at that point. You wouldnât map through its images
again, which isnât an array, youâd just use post.image.url
or whatever.
But again, I think it would be clearer just to make Products their own separate model, and query them separately apart from your regular pages. The Modular Content Field is better-suited for creating, well, sections on a page rather than generating individual pages. Not really for any technical reason, just for mental clarity. That way, you can better distinguish when youâre querying a page for its own content & sections vs when youâre trying to enumerate records to build URLs from (like for products).