Fetching articles from collection - error

Hi everyone

I’m trying to fetch blog articles from page B on page A using the collection feature. I get an error when trying this on page A:

<?php foreach($kirby->collections('articles') as $article): ?>

<article>
<h1><?= $article->title()->html() ?></h1>
<p><?= $article->text()->excerpt(300) ?></p>
<a href="<?= $article->url() ?>">Read more…</a>
</article>

<?php endforeach ?>

I have file articles.php in the folder Collections like this:

return function ($site) {
    return $site->find('pageB')->children()->listed()->flip();
};

What am I doing wrong?
(debug mode isn’t working on my local machine)

I have to correct: it’s not an error but the articles were not fetched at all, HTML renders empty.

Just found the error - it’s collection (without s), even when the folder is named collections.

Sometimes I can help myself just by posting into the forum - must be something magical here :innocent:

1 Like