Layout templates
Templates are named packages that contain scripts. They let common functionality be reused, and they fill in parts of the user interface, such as the entries in the "Add Panel" menu.
A template package contains:
metadata.json: describes the templatecontents/layout.js: the script
Templates are stored in:
/usr/share/plasma/layout-templates/~/.local/share/plasma/layout-templates/
Install one with:
kpackagetool6 --type=Plasma/LayoutTemplate -i /path/to/package
metadata.json has the usual KPluginMetaData entries, such as Name and Id, and KPackageStructure must be Plasma/LayoutTemplate. X-Plasma-Shell names the shell the template is for, and X-Plasma-ContainmentCategories says what kind of layout it is.
{
"KPlugin": {
"Id": "org.example.mypanel",
"Name": "My Panel",
"Description": "A panel with a clock"
},
"X-Plasma-ContainmentCategories": [
"panel"
],
"X-Plasma-Shell": "sonicshell",
"KPackageStructure": "Plasma/LayoutTemplate"
}
A template's script can read two global variables, templateName and templateComment. They hold the Name and Description from the file above, translated if a translation is available.
print(templateName + ": " + templateComment + "\n");
const panel = new Panel;
panel.location = "top";
panel.addWidget("org.kde.plasma.digitalclock");
Other scripts can run a panel template with loadTemplate(), which returns whether it found the template:
loadTemplate("org.example.mypanel");
Creating panels
A good example is org.kde.plasma.desktop.defaultPanel, which ships in sonic-desktop-interface/layout-templates and holds the layout of the default panel. Because it is marked as a panel template, it shows up in the "Add Panel" menu, where it creates that panel, with its widgets and configuration.
The Silver look has templates of its own in sonic-silver/layout-templates.