Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RuleCMS Widget Integration - HTML Demo

A demonstration of how to embed RuleCMS widgets in any HTML page using the <rulecms-widget> custom element. No React, Vue, Angular, or other host framework. No npm package in the page — one script tag from RuleCMS is enough.

Live Demo

View the live demo

Experience the RuleCMS HTML embed without running the page locally.

What is RuleCMS?

RuleCMS is a visual content management system that lets you:

  • Build widgets visually using a drag-and-drop composer
  • Create responsive content that works across devices
  • Publish instantly and get a unique published key for each widget
  • Embed those widgets in any HTML page with a script tag and a custom element

How widget integration works

  1. Design — Log into rulecms.com and compose a widget.
  2. Publish — RuleCMS generates a published key ({environmentId}---widget-…).
  3. Authenticate — Create an app token in project settings so the page can fetch published widgets.
  4. Embed — Load the embed script and place <rulecms-widget> with your token and published key.

The script served from https://rulecms.com/embed/… registers the custom element and already includes the default RuleCMS cards (text, image, video, and the rest of the shipped set). Your page does not install @rulecms/widget-react or register a component library.

Quick start

git clone https://github.com/rulecms/use_rulecms_example_html_project.git
cd use_rulecms_example_html_project
npm install
npm start

The page is at http://localhost:5173. Demo credentials on the <rulecms-widget> tag in index.html are enough to render the widget without extra setup. Or skip local setup and use the live demo.

Vite is only here so this teaching repo can be previewed locally and deployed to Vercel. A production host does not need Vite — copy the script tag and custom element into any HTML file.

Adding RuleCMS widgets to your own HTML page

Step 1: Load the embed script

Prefer the versioned URL in production so a new release cannot change your page unexpectedly:

<script src="https://rulecms.com/embed/widget-custom-element@0.2.0/widget-custom-element.iife.js"></script>

Optional always-latest URL (short cache):

<script src="https://rulecms.com/embed/widget-custom-element/latest/widget-custom-element.iife.js"></script>

Step 2: Place the custom element

<rulecms-widget
  token="your-app-token"
  published-key="your-published-key"
></rulecms-widget>

Step 3: Get your credentials

App token

  1. Log into rulecms.com
  2. Open project settings → API / app tokens
  3. Generate a token with widget access

Published key

  1. Create or edit a widget in the composer
  2. Click Publish
  3. Copy the generated published key

Step 4: Open the page

npm start

This demo's credentials

Demo values are attributes on <rulecms-widget> in index.html (same widget and token as the React, Vue, Angular, and Svelte examples):

  • token — app token used to fetch the widget
  • published-key — published key for the demo widget

Replace those attributes with your own token and published key when you wire this up to your site.

Understanding the embed

Piece Role
Embed script Registers <rulecms-widget> and ships the default card library
<rulecms-widget> Fetches a published widget and renders its layout tree

Attributes

  • token (required): app token from RuleCMS project settings
  • published-key (required): {environmentId}---widget-… for staging/production, or a draft widget-… key with a dev. token
  • endpoint (optional): API origin override. Leave unset so published tokens hit widget-cache and dev. tokens hit rulecms.com

The script chooses the API host from the token. You do not set endpoint in production.

Multiple widgets

Load the script once, then place as many custom elements as the page needs:

<script src="https://rulecms.com/embed/widget-custom-element@0.2.0/widget-custom-element.iife.js"></script>

<header>
  <rulecms-widget token="your-app-token" published-key="header-key"></rulecms-widget>
</header>
<main>
  <rulecms-widget token="your-app-token" published-key="main-key"></rulecms-widget>
</main>

Optional: mount with JavaScript

After the script loads, window.RuleCMS can mount into an existing node:

<div id="hero-slot"></div>
<script src="https://rulecms.com/embed/widget-custom-element@0.2.0/widget-custom-element.iife.js"></script>
<script>
  RuleCMS.mount(document.getElementById('hero-slot'), {
    token: 'your-app-token',
    publishedKey: 'your-published-key',
  });
</script>

This demo uses the declarative custom element so npm start is enough.

WordPress, PHP, and other hosts

The same two tags work anywhere you can add HTML:

  • WordPress: enqueue the script (or a header/footer plugin), then a Custom HTML block for <rulecms-widget>
  • PHP / Rails / any CMS: print the script once and output the element with escaped token and key values
  • Webflow / static hosts: paste both tags into an embed / custom-code block

See HTML Custom Element Embed for WordPress and Angular-shell notes.

Troubleshooting

Widget not displaying

  • Confirm token and published-key on <rulecms-widget> in index.html
  • Confirm the embed script returns HTTP 200 from rulecms.com/embed/…
  • Check the browser console

Error loading widget / 401

  • Wrong or disabled token, or the token environment does not match the published key

Custom team components missing

  • The HTML embed ships the default card library. For custom libraries, use @rulecms/widget-react in a React host

Scripts

Command What it does
npm start Dev server at http://localhost:5173
npm run build Production build in dist/
npm run preview Preview the production build

Project structure

use_rulecms_example_html_project/
├── index.html       # Script tag + <rulecms-widget>
├── styles.css
├── package.json     # Vite only — not required on a customer site
├── vercel.json
└── README.md

Learn more

License

MIT

About

Public HTML sample lab: embed a RuleCMS widget with a script tag and <rulecms-widget>

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages