medienbaecker / kirby-modules

Plugin for modular Kirby websites
MIT License
73 stars 7 forks source link

Add option to specify which modules to include #29

Closed shoogstoel closed 3 years ago

shoogstoel commented 3 years ago

I regularly find myself in the situation where I need 2 sets of modules sections, each with a specific set of allowed modules. Any chance this could be added?

iskrisis commented 3 years ago

Yes this would be very helpful to me as well - especially when i want to use modules for "slots" on page like Header/Footer quite powerful pattern i've discovered recently. I've been trying it out and Pages section that modules uses cannot filter pages with query. It can either set parent or filter with template. Both have problems...

Setting parent would require having multiple modules root pages and i am sure we all want the clean page>modules>all-my-modules folder structure. Also lot of the internals expect this so having page>modules-a>my-a-modules and page>modules-b>my-b-modules wouldn't cut it.

Using templates filter would probably work right now already but it's dumb because you would have to use different templates for each Modules section for this to work correctly. It might work in some rare occasions but not in general.

The best approach how to do this seem to me would be to create holding "subpages" for the modules inside the modules folder like page>modules>a-modules>my-a-modules and page>modules>b-modules>my-b-modules. Now i am not sure how this would conflict with overall logic of modules but maybe it could even work along side normal "default" modules if it's filtered out properly.

I don't have time right now but i will want this in upcoming 3 months so i might have a go at this at some point.

medienbaecker commented 3 years ago

I like this idea. Some things to keep in mind:

  1. The modules container creator will have to be aware of this additional modules container.
  2. While it's easily possible to set another parent, I'm wondering how to deal with two different sets of allowed modules. I'm not a fan of manually adding a module name to multiple files every time I add or rename a module.
  3. The ->modules() method will have to accept a parameter or so to differentiate between the different module containers.
shoogstoel commented 3 years ago

Very good points guys. My use case is quite simple and makes it a lot easier. I never have more than 1 modules section on a single page.

To give an example: Let's say you have a page blueprint called legal which only allows simple text and image modules to be used. The default page template's module section allows all modules to be used. For that rather simple use case, a change along the following would work just fine:

'templates' => function($templates = null) use (&$blueprints) {
    return $templates !== null ? Yaml::decode($templates) : $blueprints;
},

But, as I said, I really didn't think of your use case @iskrisis

medienbaecker commented 3 years ago

@shoogstoel Then your use case is already possible.

# site/blueprints/pages/default.yml
sections:
  modules: true
# site/blueprints/pages/legal.yml
sections:
  modules:
    create:
      - module.text
      - module.image
shoogstoel commented 3 years ago

You're right. I was using an old (very old I'm afraid) version of your plugin.