dps123 Posted March 24, 2016 Posted March 24, 2016 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?
kongondo Posted March 24, 2016 Posted March 24, 2016 (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 March 24, 2016 by kongondo
dps123 Posted March 24, 2016 Author Posted March 24, 2016 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.
horst Posted March 24, 2016 Posted March 24, 2016 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, ... 4
kongondo Posted March 24, 2016 Posted March 24, 2016 What @horst said. As a btw, if in a module, you also have the option of $this->sanitizer 2
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now