Newsletter
Join the Community
Subscribe to our newsletter for the latest news and updates
Astro 6 boilerplate with Directus headless CMS, featuring visual editing, draft preview, and a dynamic page builder.
The Astro CMS Template with Directus Integration is a boilerplate for building CMS-powered websites on Astro 6 with Directus as the backend, providing file-based routing, visual editing, and live preview out of the box.
This starter repository from Directus Labs pairs Astro 6 (with file-based routing) with the Directus headless CMS, using Tailwind CSS and Shadcn-style components for the UI and TypeScript for type safety. The template takes a Directus project URL and an API token as input, and produces a server-rendered Astro site with blog, dynamic pages, forms, and search. It also includes a dynamic page builder that renders CMS-defined blocks (Hero, Gallery, Posts, Pricing, RichText, etc.) into Astro pages.
[...permalink].astro and blog/[slug].astro) are defined as files, mapping URLs directly to the page structure.src/lib/directus/fetchers.ts.published/draft version keys; preview URLs with version=draft load unpublished content, and visual editing highlights CMS blocks.PageBuilder.astro component assembles configurable blocks (Hero, Gallery, Posts, Form, Pricing, RichText, ButtonGroup) into pages, with React versions of each block for visual editing.src/components/ui (including ThemeToggle, SearchModal, ShareDialog).generate:types script uses directus-sdk-typegen to generate TypeScript types from your Directus schema..nvmrc for Node version) and includes ESLint and Biome for linting and formatting.PUBLIC_DIRECTUS_URL, PUBLIC_SITE_URL, DIRECTUS_SERVER_TOKEN, PUBLIC_ENABLE_VISUAL_EDITING); Netlify deployment is supported with an adapter swap./blog/[slug]) and Directus-driven content, with live preview for draft articles.DynamicForm and FormBuilder, and store submissions back to Directus.src/pages/api/search.ts endpoint provides API-based search across your content.After cloning the repo, you copy .env.example to .env and set the Directus URL, site URL, and server token. Run pnpm install and pnpm run dev to start the site at localhost:3000. To generate TypeScript types for your Directus schema, run pnpm run generate:types, which prompts for an admin token (or uses DIRECTUS_ADMIN_TOKEN). The template only needs a server-side token for preview/draft/form features — with a licensed Directus instance you can use a user token scoped to the Live Preview and Forms policies.
Yes. The template implements Directus Draft Mode, so preview URLs with version=draft (or a custom version key) fetch the draft from the API, while version=published (or legacy version=main) loads live content. Visual editing is enabled by default via PUBLIC_ENABLE_VISUAL_EDITING.
Directus Cloud requires HTTPS for previews, so local previews need an HTTPS tunnel (e.g., ngrok or localtunnel) and proper CSP headers. For self-hosted setups, the .env.example includes CSP configuration; details are in the Directus README troubleshooting section.
Yes, but it is preconfigured for Vercel. To deploy on Netlify, install @astrojs/netlify, swap the adapter in astro.config.ts, and redeploy. The repo also includes a Vercel one-click deploy button.
Run pnpm run generate:types. It requires an admin token with permission to read system collections like directus_fields; you can provide it interactively or set DIRECTUS_ADMIN_TOKEN in the environment for CI.
Yes. You need a Directus instance (cloud or self-hosted), set PUBLIC_DIRECTUS_URL to its URL, and configure the server token. For preview, Directus Cloud requires HTTPS, and the template's CSP must include your site domain.
