any help on this one appreciated.

I have an entry url that is automated to take several fields and make the the uri.

It pulls the jobTitle, jobCity and jobId fields and then... well... this:

jobs/{jobTitle|lower|url_encode|replace("%20", "-")|replace("%2C","")|replace("%80","")|replace("%E2","")|replace("%8B", "")}-{jobCity|lower|url_encode|replace("%20", "-")|replace("%27", "")}-{jobId}

As you can see... it is a tad... long.

The problem I have is the % stuff that creeps in. Some times the job titles have odd characters that the url encode converts into % symbols. These then break the url and stop craft from displaying the page.

My short term solution has been to add lots of replace's for each one, but is there way to make a replace that uses a wildcard - so if it sees % it replaces the next two characters as well?

Something like:

|replace("%wildcard","-") etc

The current replaces work, but it just feels unwieldy.

Many thanks for any advice.

  • 5
    Might the kebab filter do what you're after? As in {jobTitle|kebab} that is.
    – megatrond
    Aug 10 '15 at 13:36

I'm just gonna post my comment as an answer, because I think it's the way to go.

I'd use the kebab filter instead of url_encode, like this: {jobTitle|kebab}

  • Thank you Megatrond, I didn't know about this one, I'll give it a go now!
    – Pathfinder
    Aug 11 '15 at 12:11
  • Yes, this worked a treat. Much cleaner code! Many thanks. jobs/{jobTitle|kebab}-{jobCity|kebab}-{jobId|kebab}
    – Pathfinder
    Aug 11 '15 at 12:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.