URL-appendix / slug generated from multiple fields

Is it possible, when I save changes to a page in panel, to autofill the URL-appendix from multiple fields?

My blueprint is:

brand:
    type:  text

american_code:
    type:  tags

european_code:
    type: tags

A sample content.txt page would be:

brand: Telefunken
----
american_code: 12ax7
----
european_code: ecc83
----

I would like the URL-appendix, when I save the page from panel, to be automatically updated to:

http://www.website.com/folder/telefunken-12ax7-ecc83

Thanks!

It could be done via a panel.page.update hook, but I’m not sure what happens in the panel if the page is moved, you’ll probably get an error message, because the file you are currently editing suddenly doesn’t exist anymore.

You could do it with a route and a model though. Instead of actually renaming the page, a route would find the item based on the values of the pages. You can then use a page model that overrides the uid() method with your custom URL structure so that the links to the pages are correct.

1 Like

I am asking because I will have one folder full if thousands of products, dozens of which with the same brand:

tubes/telefunken_12ax7
tubes/telefunken_12ax7_smooth-plate
tubes/telefunken_12ax7_ribbed-plate
tubes/telefunken_12ax7_m81
tubes/telefunken_12ax7_ecc83

It would then be handy for me to have the actual folder name to be build from

brand()_tag()_tubecode()

In this case, @lukasbestle’s suggestion will not work, because you cannot create pages with the same uid. Is there a reason why you don’t want to create the correct name for the folder at page creation?

How about the panel.page.update? Can you point me closer to the file / section I should look at? I’ve tried searching for panel.page.update through the project, but I couldn’t really tell / find if there is a specific section that rules how to write URL-appendix.

You would still have the same problem as with the panel.page.create. As soon as the page is renamed by the hook action, you would get an error in the panel, because the link to the page you are editing would no longer exist. I cannot recommend this because of bad user experience.

You can find the hook documentation here

To rename a page url, use $page->move().