Kirby Modules 2.0

I just released Kirby Modules 2.0 with some exciting new features:

:file_folder: Put module blueprints and templates in separate folders inside site/modules to easily reuse and share them
:bulb: Preview draft modules on their respective pages with the native token you get via the panel preview link
:rocket: Autopublish modules
:brain: Custom global module models
:globe_with_meridians: Globally translatable headline and empty options
:rewind: Backwards compatibility for old modules in site/snippets/modules and site/blueprints/pages

Thanks to Florian, Timo and Pedro for the help! :heart:

8 Likes

Congrats! Looking like a great update.

1 Like

Indeed, this sounds amazing!

1 Like

Could you please explain a little bit more in detail for not-native-web-developers what is possible with this plugin? thx a lot =)

Modules are subpages whose purpose is to provide the content for their parent container pages. Think of a page type “one-pager” made up of different sections (of course, such a website can consist of many such one-pager type pages, not just one).

While using normal subpages for this purpose works, you easily run into issues if the page has regular subpages as well.

The modules plugin helps to avoid such issues, by storing these “section/module” subpages in a separate subfolder, that you can then easily ignore when calling the normal subpages.

If you pursue such an approach without the plugin, you can of course do that, but then you have to create or own routes to prevent the modules folder and its children from being accessed directly via the URL.

Plus some other goodies… as listed above in the feature list.

Thus, the modules plugin is another approach to modularizing content and can be mixed with the page builder and the editor to give you maximum flexibility when building complex sites.

In case you have missed it: The builder is coming to Kirby’s core in the next big release.

6 Likes

Couldn’t have explained it better, Sonja :raised_hands:

Thx a lot… this helps me

Thank you for this! Loving it so far.

One question, how can I to get the modules in a json representation for a page?

@RustyDev The plugin registers templates and blueprints for the modules you add to the site/modules folder as e.g. module.text.yml and module.text.php.

So I think you should be able to create a template called module.text.json.php for the JSON representation. Maybe it’s a good idea to allow such representations in the site/modules folder :thinking:

1 Like

Thank you @thguenther.
Modularity is very cool!

But I’m doing something wrong.
The plugin is installed.
Created a template and blueprint in modules/text/.
Added text modules to the panel.
Code added to the parent page template
<?php $page->renderModules() ?>

Text module template modules/text/text.php

<h2 class="uk-h3"><?= $module->title() ?></h2>
<div class="uk-card-body uk-card-small" id="<?= $module->uid() ?>">
    <?= $module->text()->kt() ?>
</div>

At the front, only title are displayed.
The text field is not displayed.

@obrsk Thank you, I’m glad you like it.

What does the content file of the module look like?

Added text modules to the panel.

I’m also not 100% sure what you mean by this.

1 Like

I decided everything.
Found errors in the fields.

Thanks a lot. Waiting for it to be in the core of Kirby

awesome work. thanks!

@thguenther After a local update to the latest Kirby release, I run into errors when using the Modules plugin. I have a bit of a strange arrangement on a website where a module has sub-pages and I used to run through the collection and output them on the parent site as a list. This worked till now with:

<?php $jobs = $site->find('karriere')->modules()->find('stellen')->children()->listed() ?>  

I get now an error:

Call to a member function children() on null

…and suspect I’m doing something rather stupid by perhaps using find() on the modules. I have the same problem when trying to output this module on the home page where I use:

<?php $site->find('karriere')->modules()->find('stellen')->renderModule() ?>

to get to said module. Do you have an idea what I’m doing wrong here? Or what has changed since the update.

Thanks in advance!

Sorry for the late reply, I have been on vacation.

I think using find() you’d have to use the full id, so something like this:

$site->find('karriere')->modules()->find('karriere/modules/stellen')->renderModule()

Alternatively you can use findBy():

$site->find('karriere')->modules()->findBy('uid', 'stellen')->renderModule()

Generally I’d recommend checking for the existence of the page and module before blindly working with it. A quick and dirty but more robust solution:

if($karrierePage = $site->find('karriere')) {
  if($stellenModule = $karrierePage->modules()->findBy('uid', 'stellen')) {
    $stellenModule->renderModule();
  }
}
1 Like

Thanks a lot for the reply. Yes, I was pressed by time so I went and changed the whole logic of how I list the contents in this case (basically used no module) and solved the problem. I think your explanation is still relevant for future use and I shall keep that in mind. Thanks and thanks for the plugin!