Extend Kirby Classes

I want to integrate another template engine into Kirby. Therefore I need to extend the page and the block class. I tried the way described in the docs:

But I only get the core objects in my templates not the extended.

Here is the part if my code (index.php)

Kirby::plugin('vendor/tpl', [
    'pageModels' => [
        'default' => \vendor\Tpl\Kirby\Page::class,
    'blockModels' => [
        'Kirby\\Cms\\Block' => \vendor\Tpl\Kirby\Block::class,

I also tried to locate the new classes in the index.php or use the load helper to prevent autoloading issues. But nothing works.

What am I doing wrong? Any ideas?

Require or load, the pass the className as value, example:

require __DIR__ . '/models/Gallery.php';
require __DIR__ . '/models/GalleryImage.php';

Kirby::plugin('cookbook/virtual-gallery', [
  'pageModels' => [
    'gallery'      => 'GalleryPage',
    'gallery-image' => 'GalleryImagePage',

Thanks for your reply. But that does not help. As I wrote: I also tried to define the class in the index.php without any effect. I get a core page object in my template…

Are you using the default template or a different one? Keep in mind that models are tied to a page by template. So the DefaultPage model would only apply to pages with the default blueprint/template.

Don’t quite know where you are heading, but why are you using a page model here?

Yes, it’s a default page. default.yml and default.php are used in this case.

BTW: This example also does not work:

The index.php is loaded (I can provoke an error) but

<?= get_class($data).':'.$data->id() ?>

in my block snippet returns


and not


what I would expect.

This is how you register block models:

I tried that without success. For both: pages and blocks.

And I need to extend the base classes - so I need the second example from the docs working.

Is there any working example anywhere available?

I just tested the example from the docs and it gives me a DefaultBlock object, which is exactly what I would expect.

I also know that the code example I posted above with the GalleryPage model works as advertised, I’ve done this many times.

Ah, composer seems to be the problem.

I downloaded plain kit. With downloaded version the example works. With composer version it does not.

Any idea, how to fix that? The documentation just refers to autoload topics. As the example only has an index.php, there is no autoloading needed. Or am I wrong?–

Thanks in advance!

Ok, I got it. Using the plugin kit was the solution.

Thank you for your kind support!