Spanish Total.js
English
Documentation For AI agents
Contents

The widget file

The sections of a widget file and what CMS does with each one.

.md GitHub
On this page

A widget is one HTML file made of sections. Each section is a tag at the top level of the file:

<script total>
    // Server script: the identifier, the name and the optional server functions
    exports.id = 'mywidget';
    exports.name = 'My widget';
</script>

<style>
    /* Styles of the widget */
</style>

<settings>
    <!-- The settings form, with its own <script> -->
</settings>

<body>
    <!-- The HTML that the editor adds to the page -->
</body>

<script>
    // Script for the public pages
</script>

<template>
    <!-- A template that the server script can use -->
</template>

Only <script total> is required, with at least exports.id and exports.name. The order of the sections does not matter.

The sections

SectionWhat it holdsWhere it runs
<script total>The identifier, name, author, version, preview, default configuration, dependencies and the optional functions render, install and uninstall.On the server. See Widget file reference.
<style>The CSS of the widget.In the editor and on every public page. See Styles and assets.
<settings>The HTML of the settings form and a <script> with load, save and check.In the admin, in Widget settings. See Settings and their form.
<body>The initial HTML of an instance, with the classes that make parts editable.It is copied into the page when the user adds the widget. See Editable content.
<script>JavaScript for the visitors.On every public page that uses a layout.
<template>Any text, usually HTML with a Tangular template.It is given to render as opt.template. See Rendering on the public site.

CMS reads the <settings> section first, so the <style> and <script> tags inside it stay part of the form. For the other sections it takes the first matching tag of the file.

The CLASS placeholder

Write CLASS wherever you need a class name of your own. CMS replaces it with w- and the identifier of the widget, without dashes, in <style>, <settings>, <body>, <script> and <template>. For the identifier greeting, .CLASS-box becomes .w-greeting-box.

The editor also wraps each instance in a div with the class w-<identifier>, so .CLASS alone selects the wrapper of every instance. CMS does not replace CLASS in <script total>.

How CMS stores an instance

When the user adds a widget, the editor inserts its <body> into the page inside a wrapper:

<div class="CMS_widget CMS_remove w-greeting CMS_mv CMS_mh" data-cms="greeting__%7B%22name%22%3A%22World%22%2C%22align%22%3A%22left%22%7D" data-cms-id="mwnhgevf">
    <div class="w-greeting-box"><span class="CMS_edit">Hello</span> <b>World</b></div>
</div>
  • data-cms holds the identifier of the widget, two underscores and the configuration of the instance as URL-encoded JSON.
  • data-cms-id is the identifier of the instance.
  • CMS_mv and CMS_mh are the vertical and horizontal margins that the user switches in the floating panel. The layout gives them their size.

The page keeps this HTML. Changing the widget file later changes its styles, scripts, settings form and render for every instance, but not the HTML of instances already on pages. New instances get the new <body>.

Made in Europe