To integrate Marble in your Astro application, you first need an Astro site. If you don’t have one, you can check out the Astro documentation to get started, or use our Astro blog template for a ready-to-go solution. Astro’s Content Collections are the best way to manage content in your project. We’ll use a Content Loader to fetch your posts from Marble and make them available in your Astro site with full type-safety. You can learn more about this in the Astro Content Collections documentation.Documentation Index
Fetch the complete documentation index at: https://docs.marblecms.com/llms.txt
Use this file to discover all available pages before exploring further.
Set up environment variables
Add your Marble API key to your environment variables. Create a
.env file in the root of your Astro project:.env
Configure your content collection
Define your content collection with a loader that uses the Marble SDK. Create a file named
src/content.config.ts:src/content.config.ts
Display a list of posts
Use
getCollection() to fetch all your posts and display them on a page. Create a file at src/pages/blog/index.astro:src/pages/blog/index.astro
Display a single post
Create a dynamic route at
src/pages/blog/[...slug].astro to display individual posts: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.