Trouble querying content with 11ty

30 repliesLast updated: Nov 29, 2025

Heya, I’m trying to make my first site using sanity. I want to use Eleventy as my frontend but I’m having trouble querying the content from my database. Are there any specific guides for eleventy and sanity?
AI Update

Great to hear you're getting started with Sanity and Eleventy! There's actually a really helpful official guide from Sanity specifically for this combination.

Official Eleventy + Sanity Guide

Sanity has an official guide for getting started with the 11ty (Eleventy) Blog Starter. This guide walks you through:

How to Query Content from Sanity

The key to pulling content from Sanity into Eleventy is using 11ty's global data pattern. In the starter template, you'll find JavaScript files in the _data directory that fetch content from Sanity's API using GROQ queries.

Here's the basic approach:

For example, if you have posts.js in your _data folder, you can access that data in your Nunjucks templates as {{ posts }}.

The guide includes practical examples of:

Additional Resources

There's also a follow-up guide on adding promotional images to extend your site further.

The combination of Eleventy and Sanity gives you a lot of flexibility - Eleventy handles your static site generation with minimal dependencies, while Sanity provides structured content with collaborative features and a global CDN for assets. Good luck with your first site!

Show original thread
30 replies

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.

Related contributions