medienbaecker / kirby-modules

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

Add intelligent `modules()` method #22

Closed medienbaecker closed 3 years ago

medienbaecker commented 3 years ago

It would be great to have a modules() method which would work like the renderModules() method but also allow loops.

<?= $page->modules() ?>
<?php
foreach ($page->modules() as $module) {
  // Do something with the module
}
?>
pedroborges commented 3 years ago
Screen Shot 2020-09-29 at 18 41 03

I did a quick proof-of-concept and it works. Kirby has the Kirby\Cms\Pages collection class. I created a basic ModulesCollection class that extends Pages and implements the toString method by rendering all modules. toArray() is already taken care of by the Pages class.

Creating a modules page method that returns an instance of ModulesCollection would do the trick.

Let me know if you would be interested in a PR.

medienbaecker commented 3 years ago

That sounds really promising, Pedro! This way the modules plugin would work like the new builder 👍