PHPackages                             bnomei/autoloader-for-kirby - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. bnomei/autoloader-for-kirby

ActiveProject[Utility &amp; Helpers](/categories/utility)

bnomei/autoloader-for-kirby
===========================

Helper to automatically load various Kirby extensions in a plugin

5.0.0(1y ago)185.7k↓50%22MITPHPPHP &gt;=8.2.0

Since Aug 31Pushed 1y ago2 watchersCompare

[ Source](https://github.com/bnomei/autoloader-for-kirby)[ Packagist](https://packagist.org/packages/bnomei/autoloader-for-kirby)[ RSS](/packages/bnomei-autoloader-for-kirby/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (8)Versions (38)Used By (2)

Autoloader for Kirby
====================

[](#autoloader-for-kirby)

[![Kirby 5](https://camo.githubusercontent.com/b1a1b2ccd58e96259a9722c2489d91f40378c01b6c4c3e9fd27ed1d12c269d7c/68747470733a2f2f666c61742e62616467656e2e6e65742f62616467652f4b697262792f353f636f6c6f723d454343373438)](https://getkirby.com)[![PHP 8.2](https://camo.githubusercontent.com/fd050028b4459f3f6e4db5703412957375ceb180d27951213d421eb2a23c8c8e/68747470733a2f2f666c61742e62616467656e2e6e65742f62616467652f5048502f382e323f636f6c6f723d3445354239332669636f6e3d706870266c6162656c)](https://camo.githubusercontent.com/fd050028b4459f3f6e4db5703412957375ceb180d27951213d421eb2a23c8c8e/68747470733a2f2f666c61742e62616467656e2e6e65742f62616467652f5048502f382e323f636f6c6f723d3445354239332669636f6e3d706870266c6162656c)[![Release](https://camo.githubusercontent.com/f6021aed33a76c3b66c5bf764a41b8265eb5e2fb09b29a36f88fce362215ff3a/68747470733a2f2f666c61742e62616467656e2e6e65742f7061636b61676973742f762f626e6f6d65692f6175746f6c6f616465722d666f722d6b697262793f636f6c6f723d6165383166662669636f6e3d676974687562266c6162656c)](https://camo.githubusercontent.com/f6021aed33a76c3b66c5bf764a41b8265eb5e2fb09b29a36f88fce362215ff3a/68747470733a2f2f666c61742e62616467656e2e6e65742f7061636b61676973742f762f626e6f6d65692f6175746f6c6f616465722d666f722d6b697262793f636f6c6f723d6165383166662669636f6e3d676974687562266c6162656c)[![Downloads](https://camo.githubusercontent.com/4b3bad46cc907705573d4c4aa84341a53bc2fede3c147ea29018db6d6d56675f/68747470733a2f2f666c61742e62616467656e2e6e65742f7061636b61676973742f64742f626e6f6d65692f6175746f6c6f616465722d666f722d6b697262793f636f6c6f723d3237323832322669636f6e3d676974687562266c6162656c)](https://camo.githubusercontent.com/4b3bad46cc907705573d4c4aa84341a53bc2fede3c147ea29018db6d6d56675f/68747470733a2f2f666c61742e62616467656e2e6e65742f7061636b61676973742f64742f626e6f6d65692f6175746f6c6f616465722d666f722d6b697262793f636f6c6f723d3237323832322669636f6e3d676974687562266c6162656c)[![Coverage](https://camo.githubusercontent.com/3b9d3ba219b6035df3b160994f9994221b16745163d729d0b9a5a7f4a4d15780/68747470733a2f2f666c61742e62616467656e2e6e65742f636f6465636c696d6174652f636f7665726167652f626e6f6d65692f6175746f6c6f616465722d666f722d6b697262793f69636f6e3d636f6465636c696d617465266c6162656c)](https://codeclimate.com/github/bnomei/autoloader-for-kirby)[![Maintainability](https://camo.githubusercontent.com/a3b3123ba7efa0d8a76168bd37375528ca75a0379d836a0b589cabef19ff0a32/68747470733a2f2f666c61742e62616467656e2e6e65742f636f6465636c696d6174652f6d61696e7461696e6162696c6974792f626e6f6d65692f6175746f6c6f616465722d666f722d6b697262793f69636f6e3d636f6465636c696d617465266c6162656c)](https://codeclimate.com/github/bnomei/autoloader-for-kirby/issues)[![Discord](https://camo.githubusercontent.com/36eaef1b06f4996feb7587aa3281dcbd658e57535bc6b5e10110ed108e7a7a03/68747470733a2f2f666c61742e62616467656e2e6e65742f62616467652f646973636f72642f626e6f6d65693f636f6c6f723d3732383964612669636f6e3d646973636f7264266c6162656c)](https://discordapp.com/users/bnomei)[![Buymecoffee](https://camo.githubusercontent.com/62e55d1129b82bf9c2fd4656451e81ab87a9787e7c9676ca58276532ed9666ee/68747470733a2f2f666c61742e62616467656e2e6e65742f62616467652f69636f6e2f646f6e6174653f69636f6e3d6275796d6561636f6666656526636f6c6f723d464638313346266c6162656c)](https://www.buymeacoffee.com/bnomei)

Helper to automatically load various Kirby extensions in a plugin

Installation
------------

[](#installation)

```
composer require bnomei/autoloader-for-kirby
```

This package is NOT a Kirby plugin
----------------------------------

[](#this-package-is-not-a-kirby-plugin)

This is a composer package because it is easier to set up and does not mess with the loading order of extensions.

- Being a package, it can also be used not only for local plugins but also as a composer dependency within plugins published online.

### Autoloading of extensions

[](#autoloading-of-extensions)

Add the autoloader for each extension type you want once, and it will correctly register all files in subfolders.

#### Supported Extensions

[](#supported-extensions)

The following extensions can be autoloaded:

- blueprints (php or yml, classes)
- classes (php)
- collections (php)
- commands (php)
- controllers (php)
- blockModels (php)
- pageModels (php)
- routes (php)
- api/routes (php)
- userModels (php)
- snippets (php)
- templates (php)
- translations (php or yml or json)

#### Notes

[](#notes)

- Loading translations from YAML or JSON files are added by this package and is not originally part of Kirby core.
- The `classes` autoloader is very basic. It is recommended that you use a custom array with Kirby's `load()` helper or composers psr-4 autoloading.
- The `routes` and `apiRoutes` autoloader is based on code from @tobimori and needs a file structure similar to Next.js [see examples](https://github.com/bnomei/autoloader-for-kirby/blob/main/tests/site/plugins/routastic).
- Blueprints loaded from classes need the [kirby-blueprints](https://github.com/bnomei/kirby-blueprints) plugin

Usage
-----

[](#usage)

After requiring it as a dependency in either your project or plugin `composer.json` you can use the `autoload()`-helper to load various extension.

**/site/plugins/example/index.php**

```
