Kirby Modules plugin - get first module

How can I get just the first module with the Kirby Modules plugin?

I tried <?= $pages->modules()->limit(1) ?> and <?= $pages->modules()->first() ?> but neither worked.

Any ideas?


$page not $pages

Hmm. That doesn’t work. I actually have it in a loop on a home page. I’m trying to get a random page in the work section then display the first module on that page:

<?php foreach($site->find('work')->children()->unscheduled()->shuffle()->limit(1) as $work): ?>
<header><h1><?= $work->title()->html() ?></h1></header>
<?php $work->moduleList()->first(); ?>
<?php endforeach ?>

You don’t like the plugin readme, do you?

<?php $work->moduleList()->first()->render($data = [], $return = false);?>

Well i did read them, I didn’t realise that’s how it worked, thats all.

Honestly I read that readme file every time I need to set the plugin up every couple months and it’s very incomplete as explanatory text…


1 Like

I can’t remember all the details either and have to return to the documentation when I want to use the plugin or answer your questions.

But what exactly do you think is missing from the plugin documentation? The above example is taken from the readme…