Skip to content

Kirby 5.0.4

$page->update()

Updates the page data

$page->update(array|null $input = null, string|null $languageCode = null, bool $validate = false): Kirby\Cms\Page

Parameters

Name Type Default
$input arrayornull null
$languageCode stringornull null
$validate bool false

Return type

Kirby\Cms\Page

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

Parent class

Kirby\Cms\Page

Examples

try {

  $newPage = page('mypage')->update([
    'title'        => 'A new title',
    'text'         => 'Some text',
    'anotherfield' => 'Some more data'
  ]);

  echo 'The page has been updated:';

} catch(Exception $e) {

  echo $e->getMessage();

}

Updating a field by callback

$newPage = $page->update([
  'title' => function($title) {
    return Str::lower($title);
  }
]);

Multi-language site

Use the optional $lang parameter to specify the language you want to update.

try {

  $newPage = page('mypage')->update([
    'title'        => 'A new title',
    'text'         => 'Some text',
    'anotherfield' => 'Some more data'
  ], 'en');

  echo 'The page has been updated';

} catch(Exception $e) {

  echo $e->getMessage();

}