Plugins: Combine fields, widgets, methods

With the glimpse of the new panel widgets ( ), I started wondering again how to realize bigger plugins with Kirby. While it works for smaller plugins really well to put the plugin either in a fields folder or a widget folder or… how about plugins that actually want to add several of such functionalities?

How would you realize plugins that bring their own panel form field, field methods, panel widgets, tags and possibly even some necessary css and js for e.g. the tags? It would be great to still have one folder to copy to the plugins directory… at the moment I see only the way to tell your plugin users to copy a lot of folder to a lot of places.

Any thoughts on this? Solutions? Shared feelings and wishes or opposing comments? :slight_smile:


I agree it’d be nice if we could self contain plugins into one master folder. I don’t think its possible right now but if Kirby checked plugin directories for “widgets, fields, etc” after it checks the site directory for the same, that would be the ideal implementation in my eyes. It’d turn each plugin into an extension of the site directory.

Edit: Fields are proving far more difficult than the widget example below was. I’ll let you know if I find a solution, otherwise it may be a Bastian problem. :wink:

Here’s an example of extending the dashboard to build widgets from plugin directories as well, though it involves modifying the core files directly.



class DashboardController extends Controller {

  public function index() {

    $site    = site();
    $widgets = array();
    $wroot   = kirby()->roots()->widgets();
    $wdirs   = dir::read($wroot);

    // for plugins
    $proot   = kirby()->roots()->plugins();
    $pdirs   = dir::read($proot);

    // fetch all top-level pages in the right order
    $blueprint = blueprint::find($site);
    $pages     = api::subpages($site->children(), $blueprint);

    foreach($wdirs as $dir) {
      $file = $wroot . DS . $dir . DS . $dir . '.php';
      if(file_exists($file)) {
        $widgets[$dir] = require($file);

    // for plugins
    foreach($pdirs as $dir) {
      $file = $proot . DS . $dir . DS . 'widgets' . DS . $dir . '.php';
      if(file_exists($file)) {
        $widgets[$dir] = require($file);

    return view('dashboard/index', array(
      'topbar' => new Snippet('pages/topbar', array(
        'breadcrumb' => new Snippet('breadcrumb'),
        'search'     => purl('pages/search/')
      'history' => history::get(),
      'site'    => $site,
      'pages'   => $pages,
      'widgets' => $widgets,
      'user'    => site()->user(),


1 Like

Thanks for this, great to know! :smile:
But of course I’d wish for something that doesn’t require plugin users to change their core files.

Well if/when we have a full fledged solution we just keep bumping the thread until Bastian adds it to the core. :smiling_imp:

Maybe @bastianallgeier has some thoughts on this? Also in addition to possible further panel hooks. We are just realizing that something as an e-commerce plugin would be difficult… or at least not really simple to install.

My last project was shipped with both widgets and customised views. It would be lovely to be able to add panel plugins easily. As it stands one needs to edit the php routes, add a controller and view, then do the same with the js. That’s a lot of core file modification.

After a few days of trying on and off, I’m declaring myself officially stumped. I can get fields to work only if I specifically declare a single plugin name, but not recursively.


Edit: I semi-withdraw that statement. It was returning illegal offsets on values, so in frustration I deleted the calls for those offsets (thinking information was being left behind) but it appears to work. I’m sure this isn’t the ideal way to do it but here’s a gist with the edited form.php for anyone interested in trying it.