Sorry, we don't support your browser.  Install a modern browser

Update page title based on `create` title format#627

The automatic title feature of Kirby 4.1 allows to automatically generate a page title according to a defined format, using other fields of the page.

I would like to keep the page title ‘synced’ to those other fields, by regenerating it after the page content gets changed. This way, the title format will always remain active for the page.

2 months ago

For now I implemented it myself using this hook:

/**
    * Regenerate title on page update if format is configured for page creation dialog
    * @see https://getkirby.com/docs/reference/panel/blueprints/page#page-creation-dialog__automatic-title-and-slug
    */
"page.update:after" => function (Page $newPage) {
    if ($title = $newPage->blueprint()->create()["title"] ?? null) {
        $title = $newPage->toSafeString($title);
        // Impersonate admin user so it works even when `changeTitle` is disallowed
        kirby()->impersonate("kirby", fn() => $newPage->changeTitle($title));
    }
},

However, I think this could be a common scenario, so it may be nice if Kirby supported this natively.

2 months ago
2 months ago

Hi Jonathan, you can use a page model to accomplish this already. Example: https://github.com/tobimori/kirby-baukasten/blob/main/site/models/images.php#L12

a month ago