Guidance on displaying images from Sanity in 11ty, including a breakdown of the <https://github.com/brob/eleventy-plugin-sanity-image/blob/main/.eleventy.js|plugin-sanity-image>.
1. We create a function which will be able to convert Sanity JSON response -> image url, which is what the
urlForfunction does. (
options.clientis the Sanity client, which we use to authenticate requests)
function urlFor(source) {
return imageUrl(options.client).image(source)
}@sanity/image-urllibrary exposes a few convenience methods to help image manipulation (cropping, resizing, format, etc on the fly). The simplest way of using this is defined in `imageUrlFor`:
urlFor(image).width(width).auto('format')As to how to use them, the repo should have examples + I would recommend reading the
11ty docs as well. (tl;dr, it's a handy way of calling a JS function from your templates)
Do you know if Sanity will be coming out with a new v3 starter for 11ty? Maybe if I can see a woking example I can figure it out from there?
.eleventy.config.jsfor now, and it should work. It might be wise to spend some more time familiarising yourself with 11ty first before coming back to the Sanity side of things.
As for a V3 ready starter, perhaps
user Y will be able to comment on an official starter, but I'm sure there will be community starters around anyways - it might be worth also asking in the 11ty Discord.
Was this answer helpful?
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.