Pages
Developer Documentation
On this page

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 template
  • contents/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.

Adapted for SonicDE from develop.kde.org/docs/plasma/scripting/templates/ by Alexander Lohnau, Carl Schwan, Chris Holland, Felipe Peter, Marius P, Mikhail Zolotukhin, Phu Nguyen, Plata Hill, Thiago Sueto, Torstein Wilhelmsen Sandvik, Yifan Zhu, Zren (Chris Holland), licensed under CC BY-SA 4.0.

Edit this page on GitHub

We use cookies to personalize content and to analyze our traffic. Please decide if you are willing to accept cookies from our website.