Jump to content

Recommended Posts

Posted

I need to format a string in the same way that ProcessWire formats the page URL as you type in the page title. Is it possible to use this function or possibly copy what it's doing?

Posted (edited)

Hi @dps123. Welcome to ProcessWire and the forums.

page URLs are formatted using the $sanitizer->pageName('Title of Page') function. Have a read here.

Edit: Unless you are talking about the JavaScript that shows the live formatting as you enter the page title?

Edited by kongondo
Posted

Thanks kongondo, I'll have a read. It's not the JavaScript live formatting, I just need to do it in PHP when I'm saving the page. Thanks again!

Edit: Actually, I remember trying this before. I'm getting this error:

Error: Call to a member function pageName() on a non-object

when doing this:

$pw_url = $sanitizer->pageName($name, true);

It's inside a custom function that I'm calling from my template.

Posted

You are calling $sanitizer in the scope of a custom function. There you need to call it with wire("sanitizer")->pageName(), or, if you need it multiple times in your function: $sanitizer = wire("sanitizer"); and afterwards you can use $sanitizer->pageName().

This behaves the same with all PW template vars, like: $config, $pages, $templates, $sanitizer, $session, ...

  • Like 4

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...