Problem with ChangeSlug() in hook

I just have the strange problem that the slug cannot be changed with the page hook. Is there something wrong with this code? The strange thing is that everything is created correctly in the file system, but the pages always have a "Slug: " in the text file. This means that I can never call the pages. Even if I click on Preview in the panel, I can’t view the page. It is in a multilingual environment.

'page.create:after' => function ($page) {
  if ( $page->intendedTemplate() == 'essigfuehrung' ) {
    $title = $page->fuehrung_datum()->toDate('d.m.Y - H:i') . ' Uhr';
    $slug = $page->fuehrung_datum()->toDate('YmdHi');
    $page->changeTitle($title);
    $page->changeSlug($slug);
  }
}

The slug is changed in a non-default language in the content file, shouldn’t happen for the default language though.

But changing the slug in a hook is not a good idea, anyway.

Please stick with English in this forum, I corrected your topic title.

Sorry for the title. But what’s a better way to change the slug instead of a Hook? I use the AddFields Plugin that the User simply pick a date and the slug must be generated through that field.

That’s better off in a page model. Overwrite the create method.

Is the page model called when the page is created? To be honest, I didn’t really understand about the page model. I create a page model with the same name as the template and then how is it called?

I have tried this but not sure how that works.

I start to think that this is a bug of the Plugin. Even when I do not a hook, the plugin creates the hook with a timestamp. But same problem here …

yes

Example: Auto-append to URL-Appendix - #3 by demlak

Only in this plugin or general? I thought the Page Model is for frontend?

In a page model you extend the Page class The model inherits all public and protected methods from this class (class inheritance) and you can add new methods or overwrite existing ones.

If you are not familiar with OOP, you can read more about it here:

Ahhh ok! Yes I have read that Cookbook, it’s really amazing!!! Ok I will give a try to it … not sure if my skills are enough for this.