Integrate MarbleCMS in your Next.js application
Set up environment variables
.env.local
file in the root of your Next.js project and add the following: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.Create API utility functions
lib/query.js
(or .ts
if you’re using TypeScript).Display a list of posts
getPosts
function in a Next.js page to fetch and display a list of your blog posts. For example, in app/blog/page.jsx
:Display a single post
app/blog/[slug]/page.jsx
. This page will use the getSinglePost
function to fetch the content for a specific post.dangerouslySetInnerHTML
We use dangerouslySetInnerHTML
to render the HTML content of your post. MarbleCMS sanitizes all HTML content before it’s sent to you, so you can be confident that it’s safe to render in your application.