Jump to content

Recommended Posts

We had the need, that the URL of some pages should only be some kind of ID. I know that there are Modules like https://modules.processwire.com/modules/process-redirect-ids/, but since we have a kind of ProCache based Static Page Generator this modules doesn't work for us.

So we created this module, which hides the name filed on pages with specific templates and which replaces the $page->name with the $page->id.

https://github.com/blue-tomato/PageUseIdAsName

  • Like 2

Share this post


Link to post
Share on other sites

The way other is to simply change the name of the page to match the ID is a hook in your ready.php

// rename page to match its page ID
$this->wire()->addHookAfter('Pages::added', function($event) {
    $p = $event->arguments[0];
    if($p->template != 'basic-page') return;
    $p->setAndSave('name', $p->id);
});

One thing to note in your module - you are hooking on "save", so it will rename it every time it is saved. If you need the other functionality of your module, perhaps you can change to Pages::added ?

Share this post


Link to post
Share on other sites

I was looking for Pages::added but didn't found it (only Page::setupNew, which didn't do that in the way I want) 😀Sure, maybe I'll change that soon.

Share this post


Link to post
Share on other sites
7 minutes ago, Markus (Blue Tomato) said:

I was looking for Pages::added but didn't found it (only Page::setupNew, which didn't do that in the way I want) 😀Sure, maybe I'll change that soon.

Don't forget Tracy's Captain Hook panel 😉

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...