Skip to content

Kirby 4.1.0

$pages->add()

Adds a single page or an entire second collection to the current collection

$pages->add(\Kirby\Cms\Pages|\Kirby\Cms\Page|string $object): Kirby\Cms\Pages

Parameters

Name Type Default
$object * Kirby\Cms\Pages|Kirby\Cms\Page|string

Return type

Kirby\Cms\Pages

This method does not modify the existing $pages object but returns a new object with the changes applied. Learn more →

Exceptions

Type Description
Kirby\Exception\InvalidArgumentException When no Page or Pages object or an ID of an existing page is passed

Parent class

Kirby\Cms\Pages

Examples

Add single page by ID

$collection = page('exhibitions')->children()->listed();
$collection->add('somepage');

Add single page by $page object

$collection = page('exhibitions')->children()->listed();
$page       = Page::create([…]);
$collection->add($page);

Add second pages collection

$collection = page('exhibitions')->children()->listed();
$collection->add(page('news')->children()->listed());