Sign in to follow this  
Followers 0
bmacnaughton

Create page name with multiple consecutive dashes

6 posts in this topic

I'm trying to create a pagename (for internal use, not for presentation to the users) with multiple dashes in the middle. Here's an excerpt of my code:

$p = new Page();

$p->template = 'template-name';
$p->name = "$prod--$variation";

ProcessWire seems to apply $sanitizer->pageName($name, true) which converts multiple dashes to a single dash so the page name doesn't have "--" in it.

How can I force it to have multiple dashes?

 

 

Edited by bmacnaughton
Show code to clarify

Share this post


Link to post
Share on other sites

Sorry if this is overly simplistic, but if that is truly all you seek to do, could you just

$url = str_replace("-", "--", $sanitizer->pageName($name, true));

 

1 person likes this

Share this post


Link to post
Share on other sites
5 minutes ago, Brian Scramlin said:

Sorry if this is overly simplistic, but if that is truly all you seek to do, could you just


$url = str_replace("-", "--", $sanitizer->pageName($name, true));

 

That doesn't actually change the page name though - I already have what I want in $name, right?

Share this post


Link to post
Share on other sites
Just now, Zeka said:

@bmacnaughton

Not sure, but maybe you are looking for 


allowDoubledReplacement (bool): Whether to allow two of the same replacement chars [-_] next to each other (default=false).

See options argument

https://processwire.com/api/ref/sanitizer/name/

That's getting there - if I were in control of $sanitizer then I'd be set. But I'm creating a page via API so my code looks like (and sorry, I should have included this):

$p = new Page();

$p->template = 'template-name';
$p->name = "$prod--$variation";

So I don't have control over calling $sanitizer - PW is doing that internally. 

Share this post


Link to post
Share on other sites

Okey, I see.

From sanitizer docs:

 * Modules may also add methods to the Sanitizer as needed i.e. $this->sanitizer->addHook('myMethod', $myClass, 'myMethod'); 

So you can add custom sanitizer method and then hook __construct method of InputfieldName and set your custom method for some pages

https://github.com/processwire/processwire/blob/master/wire/modules/Inputfield/InputfieldName.module#L19

3 people like this

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
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By benbyf
      Hello,
      Does anyone know whether the is a place detailing the structure your admin theme should take when creating one? e.g. I see UiKit, Reno and Default admin themes all have default.php, init.php, controller.php files, is this a stylisitic choice or a prerequisite for any admin theme module?
      Thanks!
    • By bmacnaughton
      I am using the translation function (either $this->_() or __()) within a module that responds to AJAX API calls - there isn't really a page that is being served.
      When I supply a string with an apostrophe, e.g.,
      __('Book \'em danno') It is formatted as
      Book 'em danno  
      Is there some way to prevent output formatting when retrieving strings using the translation functions?
    • By dweeda
      At the top of each of my main pages, I want to redirect to my login page if the session is timed out.  How can I use the PW API to test for this?
      $user->isLoggedin() doesn't seem to do it, like I expected.
      THX
    • By Sipho
      I wish to access a template's allowed templates for it's children from the API. This one:

      I am pretty sure this is possible, but I can't seem to find it anywhere in the documentation. If this is not possible, is there some way of assigning properties to templates? So like fields that already have a value on all pages using that template.
    • By louisstephens
      I have a bit of a head scratcher for myself. I have a form (first name, last name, and domain) that I use to create pages. I have the first name and last name being combined and saving as the title, and being saved in their individual fields as well. The domain name is just being saved in it's designated field under the page. This all works quite well in fact.
      (just a note: for a special case, I am combining all three values so it looks like johndoe@domainselected.com)
      However, I thought I might need to check to see if the page already existed, and if it does, provide the user with an error. If it doesn't already exist, follow through with creating the page. I didnt want to save the entire address in the title as I knew "@" wouldn't fly with the url to the page.
      I thought I could use a foreach, but I understand that outputs an array, when I need to check just one entry.
      Does anyone have any suggestions? I am probably making this much more difficult than it needs to be.
       
        I have fixed the issue... "==" seemed to fix it.