1
Set up environment variables
First, add your Marble API URL and Workspace Key to your environment variables. Create a
.env file in the root of your Astro project and add the following:.env
2
Configure your content collection
Next, define your content collection. This tells Astro how to fetch and validate your data from Marble. Create a file named
src/config.ts and add the following code.This configuration defines a posts collection, and includes a loader function that fetches your posts from the Marble API.For complete TypeScript type definitions, see our Types
reference. The schema below matches the
Post type from the API.src.config.ts
3
Display a list of posts
Now, you can use
getCollection() to fetch all your posts and display them on a page. Create a file at src/pages/blog/index.astro to list all your posts.src/pages/blog/index.astro
4
Display a single post
To display individual posts, create a dynamic route that fetches a single post based on its slug. Create a file at
src/pages/blog/[...slug].astro.This page uses getStaticPaths() to generate a static page for every post at build time.src/pages/blog/[...slug].astro
Rendering HTML ContentWe use the
set:html directive to render the post content. Marble sanitizes all HTML content on the server, ensuring it’s safe to render directly in your application.