Joint session with Vercel: How to build intelligent storefronts (May 15th)

Connecting Sanity CMS to 11ty Frontend Tutorial or Reference

7 repliesLast updated: Nov 30, 2025

Does anyone know of a reference or tutorial for connecting Sanity’s to an 11ty’s frontend? The Starters are fine, but I’d like to create it from scratch, and see how everything is connects.
Thanks.
AI Update

I can help you with connecting Sanity to Eleventy from scratch! While there's an official guide available, let me point you to the best resources and give you an overview of how everything connects.

The main tutorial you're looking for is the official Sanity guide on getting started with the 11ty Blog Starter by Bryan Robinson. While it starts with the template, it does a great job explaining the fundamental concepts of how the pieces fit together, which is exactly what you need to understand for building from scratch.

How Everything Connects

Here's the basic architecture you'll be working with:

1. Sanity Studio (Content Management)

2. Eleventy (Static Site Generator)

3. The Connection Point: Global Data Files

This is the key piece! In your _data directory, you create JavaScript files that query Sanity. Here's a simplified example of what a posts.js file might look like:

const sanityClient = require('@sanity/client')
const groq = require('groq')

const client = sanityClient({
  projectId: 'your-project-id',
  dataset: 'production',
  useCdn: true
})

module.exports = async function() {
  const query = groq`*[_type == "post"]{
    title,
    slug,
    body
  }`
  
  const posts = await client.fetch(query)
  return posts
}

4. Using the Data in Templates

Once you have the data, you can use it in your Nunjucks (or Liquid/Handlebars) templates:

{% for post in posts %}
  <h2>{{ post.title }}</h2>
{% endfor %}

Building From Scratch Steps

Additional Resources

The Sanity + Eleventy landing page explains the benefits of this stack. The guide walks through practical examples like adding excerpts to blog posts, which demonstrates the full data flow from schema → query → template.

For GROQ queries (Sanity's query language), check out the GROQ documentation to understand how to fetch exactly the data you need.

The beauty of this setup is that 11ty's flexibility means you can structure your project however you want - the key is just understanding that data flow from Sanity → JavaScript data files → 11ty templates. Once you grasp that pattern, you can build anything! The starter template is actually a great reference for seeing these patterns in action, even if you're building from scratch.

Show original thread
7 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