1
Set up environment variables
First, you’ll need to add your Marble API URL and Workspace Key to your environment variables. Create a
.env.local
file in the root of your Next.js project and add the following:.env.local
Important: Never expose your
MARBLE_WORKSPACE_KEY
in client-side code.
Your environment variables should only be accessed on the server during the
build process. For client-side updates, use webhooks to
trigger rebuilds.You can find your Workspace Key in your Marble dashboard under the settings for your workspace.
2
Create API utility functions
To make it easier to fetch data from Marble, you can create a utility file to wrap your API calls. This keeps your data-fetching logic organized and reusable.Create a file at
lib/query.ts
(or .js
if you’re using JavaScript).For complete TypeScript type definitions, see our TypeScript Types reference. The server functions below use these types for full type safety.
lib/query.ts
3
Display a list of posts
Now you can use the
getPosts
function in a Next.js page to fetch and display a list of your blog posts. For example, in app/blog/page.jsx
:app/blog/page.jsx
4
Display a single post
To display a single post, you can create a dynamic route in Next.js, for example at
app/blog/[slug]/page.jsx
. This page will use the getSinglePost
function to fetch the content for a specific post.app/blog/[slug]/page.jsx
A note on
dangerouslySetInnerHTML
We use dangerouslySetInnerHTML
to render the HTML content of your post. Marble sanitizes all HTML content before it’s sent to you, so you can be confident that it’s safe to render in your application.5
Example Styling (Optional)
To improve the appearance of your content, you can use Tailwind CSS Typography to add beautiful typographic defaults. We provide a simple Add it to your Tailwind CSS configuration. If you’re using Tailwind CSS v4:For Tailwind CSS v3, add it to your Now create a Now you can update your post page to use the This will give your content beautiful, readable typography with proper spacing, font sizes, and styling for headings, links, images, and other elements. You can customize the styles by modifying the classes in the
Prose
component that makes it easy to style your Marble content.First, install the Tailwind CSS Typography plugin:app/globals.css
tailwind.config.js
:tailwind.config.js
Prose
component that you can use to style your content. Create components/prose.tsx
:components/prose.tsx
Note: This component assumes you have a
cn
utility function for combining class names. You can install and set up clsx
or use a similar utility, or simply replace cn()
with string concatenation.Prose
component:app/blog/[slug]/page.jsx
Prose
component or by extending the typography configuration in your Tailwind config.For more information about customizing the typography styles, check out Tailwind CSS Typography!