Skip to content

Kirby 5.1.1

$kirby->collection()

Returns a specific user-defined collection by name. All relevant dependencies are automatically injected

$kirby->collection(string $name, array $options = [ ]): Kirby\Toolkit\Collection|null

Parameters

Name Type Default
$namerequired string no default value
$options array [ ]

Return types

Kirby\Toolkit\Collectionornull

This method modifies the existing $app object it is applied to and returns it again.

Parent class

Kirby\Cms\App

Examples

Call a predefined collection by key:

$articles = $kirby->collection('blog');
dump($articles);

Pass additional options

site/collections/blog-category.php
return function (string $category) {
  return page('blog')->children()->filterBy('category', $category);
}
$articles = $kirby->collection('blog-category', ['category' => 'food']);