The Big Picture
| Part | Location | Purpose |
|---|---|---|
| Widget type | widgets/{type}/ | How the widget looks and which fields it has (HTML, CSS, JS, schema.json) |
| Widget instance | widgets table | One use of a type with its own content (e.g. a "hero-card" Card) |
The type is the class, the instance is an object. Create the Card type once, then as many Card instances as you need.
Built-in types: card (image, title, description, link), image (image, alt text, caption, link), html (raw HTML block), rich-html (HTML written in a WYSIWYG editor, with images and files from the Media Manager), embed (YouTube, Vimeo, Maps, social posts and more from a pasted URL), contact-form (a name / email / message form that emails the active site's contact address).
1. Create the Widget Type
widgets/testimonial/
├── index.html required: the template
├── schema.json recommended: the fields shown in the admin form
├── style.css optional: loaded only on pages that use this type
└── script.js optional: loaded only on pages that use this type
Type names are folder names: lowercase letters, digits, dashes and underscores. A folder appears in the admin as soon as it contains index.html; no restart is needed.
schema.json: the admin form
Each field becomes an input in Admin > Widgets and a value available in the template.
{
"fields": [
{ "key": "quote", "type": "textarea", "label": "Quote" },
{ "key": "author", "type": "text", "label": "Author" },
{ "key": "photo", "type": "image", "label": "Photo" }
]
}
| Field type | Input |
|---|---|
text | Single-line text (also used for any unknown type) |
textarea | Multi-line text |
image | Image URL with a Media Manager picker (shared files plus the active site's) |
richtext | The shared content editor (CKEditor 5) producing HTML: text formatting, lists, links, tables, video, and images with text wrapping that can be resized and moved by dragging (see the overview). Its Media toolbar button picks from the Media Manager, and dropped or pasted images are uploaded to it. The field has the neutral look and no Widget or Collection buttons (shortcodes are not rendered inside widgets). Output it with {{ key | raw }}. |
index.html: the template
Widget templates use a small template syntax of their own:
{{ key }}outputs a field, HTML-escaped.{{ key | raw }}outputs it unescaped. Use only for trusted admin input (the built-in html widget does this).{{#if key}} ... {{else}} ... {{/if}}for optional content.- Only plain field names are supported: no loops (
#each) and no dotted names.
<figure class="testimonial">
{{#if photo}}<img src="{{ photo }}" alt="{{ author }}">{{/if}}
<blockquote>{{ quote }}</blockquote>
<figcaption>{{ author }}</figcaption>
</figure>
style.css and script.js
Both are optional and added to a page only when a widget of that type is on it, once per page however many instances there are. Prefix your class names with the type name to avoid clashing with the theme. script.js is plain browser JavaScript:
document.addEventListener('DOMContentLoaded', () => {
document.querySelectorAll('.testimonial').forEach((el) => {
// optional behaviour
});
});
2. Add the Type to a Site
- Copy the folder to
widgets/{type}/(for example with git), or - Upload a ZIP in Admin > Widgets > Upload Type: enter the type name and choose a ZIP containing
index.html(plusschema.json, CSS, JS, images). Zipping the widget folder itself is fine: a single wrapping folder is removed. Only web file types are accepted, and an existing type is never overwritten.
A type can be deleted in the admin only when no instances use it.
3. Create an Instance
- Go to Admin > Widgets > Add Widget.
- Choose the type; the form shows the fields from its
schema.json. - Enter a name (e.g.
hero-card). Names are unique per type. - Fill in the fields and save.
The Visible switch hides an instance everywhere without deleting it.
4. Embed It in a Page
Use either form in a theme page, a theme layout, or the content of a page from Admin > Pages. In the Pages editor, the Widget toolbar button lists every instance and inserts its shortcode for you; the Embed Code column in Admin > Widgets has a copy button too:
{{ widgets:render type="card" instance_name="hero-card" }}
[[card, hero-card]]
Both forms can override fields for one placement. Quote a value that contains spaces or commas; quotes are not part of the value:
{{ widgets:render type="card" instance_name="hero-card" title="Spring Sale" }}
[[card, hero-card, title="Spring Sale, today only", link_text=Shop now]]
Shortcodes inside a code block (<pre>, <code>, <script>, <style> or <textarea>) are shown as written, not rendered, so a page can show them as examples.
In the short form, unquoted values run until the next comma. Override values are HTML-escaped like stored ones. A missing or hidden instance renders as an HTML comment, so a page never breaks. While the Widgets module is disabled, shortcodes render nothing.
Caching: pages that contain widgets are tagged widgets in the page cache and are cleared automatically whenever a widget is saved, hidden or deleted.
Used in: Admin > Widgets lists where each instance is embedded: every theme's templates (any .html file in themes/, including subfolders) and every page in Admin > Pages, drafts included, one badge per place: pages in blue (drafts in yellow), theme templates in gray as theme · file. Hiding or deleting an instance that is used asks first, because those spots would then show nothing; the edit form shows the same list. Codes inside a code block are not counted, as they are not rendered. Code in a site's init.ts is not scanned.
5. API Reference
All widget endpoints are under /api/v1/widgets/admin/*, behind the admin gate: reading needs widgets.view, saving widgets.edit, deleting widgets.delete and showing / hiding widgets.publish (administrators always pass; managers by default). Uploading and deleting widget types is for administrators only, because a type contains HTML and JavaScript. See Roles & Permissions.
| Route | Method | Description |
|---|---|---|
/api/v1/widgets/admin/types | GET | Available widget types |
/api/v1/widgets/admin/schema/:type | GET | A type's schema.json |
/api/v1/widgets/admin/list | GET | All instances, each with usedIn: the places that embed it ({ kind: 'page' | 'template', name, theme?, draft?, label }) |
/api/v1/widgets/admin/:id | GET | One instance |
/api/v1/widgets/admin/save | POST | Create or update an instance |
/api/v1/widgets/admin/toggle-visibility | POST | Show or hide an instance |
/api/v1/widgets/admin/delete | POST | Delete an instance |
/api/v1/widgets/admin/upload-type | POST | Upload a type ZIP |
/api/v1/widgets/admin/delete-type | POST | Delete a type (only if it has no instances) |
6. Database Schema
CREATE TABLE widgets (
id TEXT PRIMARY KEY,
type TEXT NOT NULL, -- folder name in widgets/
name TEXT NOT NULL, -- instance name, unique per type
params TEXT NOT NULL DEFAULT '{}', -- JSON: the schema.json field values (never is_visible)
is_visible INTEGER NOT NULL DEFAULT 1, -- 0 = hidden everywhere
added_by TEXT NOT NULL,
date_added INTEGER NOT NULL,
date_updated INTEGER NOT NULL,
updated_by TEXT,
UNIQUE(type, name)
);
Summary
- Create
widgets/{type}/withindex.htmland aschema.json(plus optional CSS/JS). - Create instances in Admin > Widgets.
- Embed with
{{ widgets:render type="{type}" instance_name="{name}" }}or[[{type}, {name}]].