Bridge Mode
Bridge Mode overlays ClearCMS's visual editor on your custom frontend. Your frontend fetches content from the API and renders it; ClearCMS adds editing controls when an editor is logged in.
How it works
- Your frontend renders the page using content from the ClearCMS API.
- You add
bridge.jsto your page. - When a ClearCMS editor visits the page,
bridge.jssends aBRIDGE_READYmessage to the ClearCMS editor frame. - The editor activates bridge mode, overlaying edit controls based on
data-clearcms-fieldattributes. - Editors click fields to edit them inline, with complex fields opening in the right panel.
Bridge Mode is auto-detected. If bridge.js is present and BRIDGE_READY fires, the editor activates automatically.
Setup
1. Add bridge.js
Add the script to the <head> of your page:
<script src="https://your-site.clearcms.app/bridge.js" defer></script>
The script is small and has no effect on visitors not logged into ClearCMS.
2. Mark editable fields
Add data-clearcms-field attributes to editable HTML elements:
<h1 data-clearcms-field="headline">We build great software</h1>
<p data-clearcms-field="subheadline">Based in London</p>
The attribute value must match the field name in your content schema.
3. Mark the content item
Wrap editable fields in a container with data-clearcms-item and data-clearcms-type:
<article
data-clearcms-item="post_001"
data-clearcms-type="posts"
>
<h1 data-clearcms-field="title">Hello World</h1>
<div data-clearcms-field="body">
<p>Post body content here.</p>
</div>
</article>
| Attribute | Value |
|---|---|
data-clearcms-item | The content item's ID from the API |
data-clearcms-type | The content type slug (e.g. posts, team) |
data-clearcms-field | The field name within that content item |
Field types
Different field types get different editing controls:
| Field type | Editing behavior |
|---|---|
| Short text | Inline text editing directly in the element |
| Long text / rich text | Opens a text editor in the right panel |
| Image | Click to open media picker |
| URL / link | Edits in right panel |
| Array / collection | Click item to edit in right panel |
| Boolean / select | Edits in right panel |
Page-level fields
For fields that belong to a page rather than a content item, use data-clearcms-page instead:
<section
data-clearcms-page="{page-id}"
data-clearcms-section="hero"
>
<h1 data-clearcms-field="headline">Welcome</h1>
</section>
Detecting bridge mode in your frontend
To conditionally render UI when the editor is active, listen for the clearcms:ready event:
window.addEventListener('clearcms:ready', (event) => {
console.log('ClearCMS editor is active', event.detail);
// e.g. show an "exit preview" button
});
Security
bridge.js only activates when a valid ClearCMS session is present. Visitors without a session see your page as normal -- no editing UI, no extra network requests beyond the initial script load.
The script uses postMessage with origin validation. Only messages from *.clearcms.app are accepted.
Example: Next.js page
// app/blog/[slug]/page.tsx
import { notFound } from 'next/navigation';
async function getPost(slug: string) {
const res = await fetch(
`https://your-site.clearcms.app/api/v1/content/posts/${slug}`,
{ next: { revalidate: 60 } }
);
if (!res.ok) return null;
return res.json();
}
export default async function BlogPost({
params,
}: {
params: Promise<{ slug: string }>;
}) {
const { slug } = await params;
const post = await getPost(slug);
if (!post) notFound();
return (
<>
<script src="https://your-site.clearcms.app/bridge.js" defer />
<article
data-clearcms-item={post.id}
data-clearcms-type="posts"
>
<h1 data-clearcms-field="title">{post.data.title}</h1>
<div
data-clearcms-field="body"
dangerouslySetInnerHTML={{ __html: post.data.body }}
/>
</article>
</>
);
}
Troubleshooting
Editing controls don't appear
- Confirm you are logged into ClearCMS in the same browser.
- Check the browser console for
BRIDGE_READYbeing sent. - Verify the
data-clearcms-itemID matches the actual content item ID returned by the API.
Fields are not editable
- Check the
data-clearcms-fieldvalue matches the exact field name in the content schema. - Fields not defined in the schema are ignored by the editor.
Changes don't appear after saving
- Your frontend may be caching API responses. If using ISR (Next.js) or similar, trigger revalidation on content updates. ClearCMS sends a webhook on publish -- see Settings > Developer > Webhooks.