Spanish Total.js
English
Documentation For AI agents
Contents

Install widgets from files

Install your own widgets by pasting their code or from a folder of the server.

.md GitHub
On this page

The Import widgets window always shows the official catalogue. To install your own widgets, paste their code in the admin or let CMS install them from files on the server.

Paste the code

  1. Open Widgets, click Options and choose Create.
  2. Replace the template with the code of your widget.
  3. Click SUBMIT.

If a widget with the same exports.id exists, it is replaced. Use the same steps to move a widget from one CMS to another: open it with Edit, copy the code and paste it in the other CMS.

Install from a folder

If you run CMS from source, a definition file can install every widget of a folder when CMS loads its data. Create definitions/widgets.js in the CMS folder:

// Installs the widgets of the "widgets" folder when CMS loads its data
ON('reload', function() {
    F.Fs.readdir(PATH.root('widgets'), function(err, files) {
        if (err)
            return;
        files.wait(function(name, next) {
            F.plugins.widgets.create(PATH.root('widgets/' + name), function(err) {
                err && console.log('Widget', name, err);
                next();
            });
        });
    });
});

Put your widget files in a widgets folder next to index.js and restart CMS. The widgets appear on the Widgets screen.

F.plugins.widgets.create(source, [rewrite], callback) installs one widget:

  • source is the path of a file or the HTML of a widget.
  • Without rewrite, a widget that is already installed is kept as it is, so the code above installs each file only once. Pass true to replace the installed widget with the file at each start.
  • callback(err) runs when the widget is saved.

Keep widgets in version control

Keep the files of your widgets in a repository, one file for each widget, named after exports.id. That is also the format of the official repository.

Made in Europe