[Composer package] to autload extensions in plugins

I created a little helper to speed up writing plugins. It can be used locally or for public composer based plugins.

composer require bnomei/autoloader-for-kirby

/site/plugins/example/index.php

<?php

// optionally change some settings
/*
autoloader(__DIR__, [
    'snippets' => [
        'folder' => 'schnippschnapp',
    ],
]);
*/

autoloader(__DIR__)->classes();
// use a different folder
// autoloader(__DIR__)->classes('src');

Kirby::plugin('bnomei/example', [
    'options' => [
        // options
    ],
    'blueprints' => autoloader(__DIR__)->blueprints(),
    'collections' => autoloader(__DIR__)->collections(),
    'controllers' => autoloader(__DIR__)->controllers(),
    'pageModels' => autoloader(__DIR__)->pageModels(),
    'userModels' => autoloader(__DIR__)->userModels(),
    'snippets' => autoloader(__DIR__)->snippets(),
    'templates' => autoloader(__DIR__)->templates(),
    'translations' => autoloader(__DIR__)->translations(),
    // other extensions
]);

v1.3.0 has support for upcoming block models (kirby v3.6)

'blockModels' => autoloader(__DIR__)->blockModels(),

thanks to @samzzi the new version 1.4.0 has more relaxed settings about filenames. it will now load blueprints and snippets with additional dots in the filename. like /site/snippets/my.custom.snippet.php. it did only load snippets with .php and .html.php before.

if you need to change these settings read this

1 Like

v1.6.0 adds Next.js like loading for routes and api routes based on code by @tobimori

routes