Create Title from uri

panel

#1

I have a case where I need to name a lot of pages that already have properly named folders. It would be cool to reverse the “create from uri” button to make capitalized titles that convert hyphens to spaces.


#2

You can do it programatically in a loop with ->update()

Back up the content first though, incase you make a mistake :slight_smile:


#3

Please note that programmatically updating pages requires authentication.

To get rid of the hyphens, you can use str::replace()


#5

Thanks for the replies! I got it working with this:

foreach ($site->find('your/page')->children()->visible() as $page) {
  page($page)->update([
    'title' => Str::replace($page->title(),'-',' '),
    'title' => ucwords($page->title())
  ]);
}

and for anyone who might use this, if you make a mistake, you can revert the titles back to the folder name with this:

foreach ($site->find('your/page')->children()->visible() as $page) {
  page($page)->update([
    'title' => ''
  ]);
}