Install widgets from files
Install your own widgets by pasting their code or from a folder of the server.
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
- Open Widgets, click Options and choose Create.
- Replace the template with the code of your widget.
- 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:
sourceis 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. Passtrueto 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.