This plugin makes it super easy to create modular websites with Kirby.
- Modules are bundled in
site/modulesand registered as regular blueprints and templates. - Every module is available to create in the
modulessection without editing any other file. - Modules can not be accessed directly and will automatically redirect to the parent page with an anchor.
- The container page is automatically created and hidden in the panel.
- You can preview draft modules on their parent pages via the panel preview button.
A module is a regular page, differentiated from other pages by being inside a modules container. This approach makes it possible to use pages as modules without sacrificing regular subpages.
📄 Page
📄 Subpage A
📄 Subpage B
🗂 Modules
📄 Module A
📄 Module B
Module blueprints and templates live in a separate site/modules folder. This way you can easily reuse modules across projects and share them with other people.
Add a modules section to any page blueprint and a modules container will be automatically created.
You can create modules by putting them in a site/modules folder. For example you can add a site/modules/text folder with the template text.php and the blueprint text.yml.
In the parent page template you can then use <?= $page->modules() ?> to render the modules.
title: Default Page
sections:
modules: true<?= $page->modules() ?>title: Text Module
fields:
textarea: true<div class="<?= $module->moduleId() ?>" id="<?= $module->uid() ?>">
<h1><?= $module->title() ?></h1>
<?= $module->textarea()->kt() ?>
</div>You can access the module page object with $module and the parent page object with $page.
The $module->moduleId() method returns the module ID, e.g. module_text or module_gallery.
Adding a page model for the parent page(s) and overwriting the hasChildren method skips the confirmation dialog you see when deleting a page with children. You can adjust the code depending on what you want to happen when there are modules or just a modules container:
<?php
use Kirby\Cms\Page;
class DefaultPage extends Page {
public function hasChildren(): bool {
$children = $this->children()->filterBy('intendedTemplate', '!=', 'modules');
$children = $children->merge($this->grandChildren());
$children = $children->merge($this->children()->drafts());
return $children->count() > 0;
}
}Thanks to @lukaskleinschmidt for helping me with this.
By default, the text module will be the first/default option in the "Add page" modal.
You can overwrite it in your site/config/config.php:
return [
'medienbaecker.modules.default' => 'gallery'
];You can turn on automatic publishing for modules in your site/config/config.php:
return [
'medienbaecker.modules.autopublish' => true
];This plugin creates a ModulePage model, overwriting certain methods.
You can extend this model with your own model:
// site/config/config.php
return [
'medienbaecker.modules.model' => 'CustomModulePage'
];// site/models/module.php
class CustomModulePage extends ModulePage {
// methods...
}Download this repository to /site/plugins/kirby-modules.
Alternatively, you can install it with composer: composer require medienbaecker/kirby-modules
This project is licensed under the terms of the MIT license.

