How do you work with files that are not suited to put in a plugin?

Let’s say you have some plugins, snippets, maybe controllers. To work with them you need some functions or even some custom classes. How do you work with that? Where do you put them?

Custom functions in a plugin

Personally I put custom functions in here:

site/plugins/core/
site/plugins/core/core.php
site/plugins/core/routes.php
site/plugins/core/some-other-things.php

Reinvent site

Sometimes I even reinvent site like this:

site/plugins/core/
site/plugins/core/controllers/
site/plugins/core/templates/
site/plugins/core/snippets/

I could add other things like routes as well:

site/plugins/core/
site/plugins/core/controllers/
site/plugins/core/templates/
site/plugins/core/snippets/
site/plugins/core/routes/

So why do I reinvent site?

Because I get a really modular structure. If everything is in a plugin, every plugin can be seen as a module. Maybe my core plugin evolves into two plugins. Then I only register the snippets etc that is needed for that particular plugin.

If I delete a plugin, all the snippets bound to it is deleted as well and that’s really nice.

Kirby 2.4 - New possibilities

With the custom paths of Kirby 2.4, maybe I can let go of site completely and only work with module/plugin approach. I think mobile phones work the same way, everything is an app.

Be aware, I have not tried my Kirby 2.4 module approach and I don’t know if it will work as perfect as I have in my mind.

How do you do it?

1 Like

Kirby 2.4 does not change anything about that. Only thing that changes is that you can modify the roots of your main site directories.

But since you want to have everything modular anyway, you don’t need the main site directories. You can get rid of them completely and register everything from plugins. It makes the structure a lot more complex, but if the gained modularity is worth it for you, go for it.

Only thing that changes is that you can modify the roots of your main site directories.

Exactly. We should be able to have almost whatevery folder structure we want now, right?

You can get rid of them completely and register everything from plugins. It makes the structure a lot more complex

I think the complexity in this case is most of the part in the hands of Kirby which means it’s already taken care of. From my part I think it will be easier to work with one modular/plugin structure than a combination of plugins and site. Just like the Patterns plugin, it can be easier for larger sites. But it might now work for everyone.

What I see as benefits:

  • Everything will work the same.
  • Delete a plugin and all “dependencies” like snippets and controllers are gone with it.
  • I already register things in the plugins so I don’t see the increasing complexity.
  • I can have any folder structure I want inside the plugins.

but if the gained modularity is worth it for you, go for it.

When it comes to try new things I’m always really really positive. If I don’t try, how can I ever know which approach is the best? So yes, I will try it. Then we will se which approach I will take in the future. :slight_smile:

When I try new things I learn more, some new plugins are released and I even find some new bugs, ideas etc.

I’ll try to remember to get back to this topic when I’ve tried it and see how it went.

1 Like