Astro image query Issue

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! :slight_smile:)

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).