Constructs - A Plugin for Developers of Reusable Content Models

Disclaimer

This module is targetet towards developers that work with multiple Kirby sites. This module is definitely not for everybody and that is by design.

Constructs

I have developed the Kirby Constructs plugin to address some of the recurring gripes I’ve had when creating Kirby sites. It is heavily inspred by @lukasbestle’s Modules Plugin but takes things a few steps further - some will probably argue a step too far ;).

The Plugin allows me to bundle parts of a site’s content model (blueprints), templates, logic, etc. as a reusable piece of code. I really, really don’t like copy-pasting blueprints, templates and other files from one project to another just to get the same functionality even though I am most likely only going to tweak simple things like the styling.

I know that I could also achieve mostly the same result by bundling the reusable pieces into individual plugins, but then I would still have to reimplement a lot of the same mechanisms in each plugin, duplicating a lot of code. Having Constructs as an additional layer on top of plugins allows me to maintain common functionality in a central location - since I’m also not a big fan of checking in Composer vendor directories, this seemed like the cleanest solution.

Feedback

I’d love to hear some feedback on what you like / don’t like about this approach and maybe what other issues you’ve had trying to build multiple Kirby sites that this module doesn’t solve. There are also more than likely still a few “kinks” in the documentation; please let me know where things might be unclear. Any constructive criticism is always welcome.

2 Likes

Hey there,

any suggestion how to get this work with a blueprint field? I assume that your plugin should be aware of child pages of a host-page and render them by $page->components() right? I think your plugin could be useful, but how should i get it to work for a simple user, not being a developer at all. I’m kind of confused.

BTW: Your starterkit is broken. It cannot be cloned as you wrote: remote HEAD refers to nonexistent ref, unable to checkout.

Greets Tobi

Just fixed the repository issue. You should now be able to clone the repository and run the sample as described in the readme - sorry about that.

I don’t really understand your question(s) though… If you can get the starter-kit to run, you can check out the sample page in the panel UI which should give you some idea on how it all fits together. I have to warn you though - as stated in the disclaimer in the original post, this module is targeted towards developers and requires quite a bit of abstract thinking.

Most of the interesting bits of the starter-kit are actually happening in the kirby-constructs-sample submodule, which is a separate git repository included in the project. This is located in the web/site/constructs/sample-construct directory and under components/host-page (in the aforementioned directory), where you can see the blueprint and template for the host page. The template shows you how to place the child components which then take care of their own rendering since they have their own blueprints and templates.

It’s all very meta, recursive and modular :slight_smile: . A lot of it may only really start making sense to you if you understand the issues that arise when you are trying to develop and maintain many different Kirby sites that share common features on many levels.