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

<p>I'd use the <a href="http://buildwithcraft.com/docs/templating/filters#kebab" rel="nofollow"><code>kebab</code> filter</a> instead of <code>url_encode</code>, like this: <code>{jobTitle|kebab}</code></p>

CC BY-SA 3.0
2015-08-11T12:11:14.823Z
Thank you Megatrond, I didn't know about this one, I'll give it a go now!
Pathfinder
CC BY-SA 3.0
2015-08-11T12:16:26.083Z
Yes, this worked a treat. Much cleaner code! Many thanks.

    jobs/{jobTitle|kebab}-{jobCity|kebab}-{jobId|kebab}
Pathfinder
CC BY-SA 3.0
2015-08-10T17:39:02.663Z
2015-08-10T17:39:02.663Z
megatrond
<p>any help on this one appreciated.</p>

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

<p>It pulls the jobTitle, jobCity and jobId fields and then... well... this:</p>

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

<p>As you can see... it is a tad... long.</p>

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

<p>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?</p>

<p>Something like:</p>

<pre><code>|replace("%wildcard","-") etc
</code></pre>

<p>The current replaces work, but it just feels unwieldy.</p>

<p>Many thanks for any advice.</p>

CC BY-SA 3.0
2015-08-10T13:36:56.350Z
Might the [kebab filter](http://buildwithcraft.com/docs/templating/filters#kebab) do what you're after? As in `{jobTitle|kebab}` that is.
megatrond
<templating><replace>
Is it possible to create a cleaner replace?
# Is it possible to create a cleaner replace?

(Asked by: username_0 on 2015-08-10)

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.

**Tags:** templating, replace

> **Comments:**
> **username_1**: Might the [kebab filter](http://buildwithcraft.com/docs/templating/filters#kebab) do what you're after? As in `{jobTitle|kebab}` that is.  

---

## 1 answers

### Answer by username_1 on 2015-08-10. Score: 3 | Accepted answer

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](http://buildwithcraft.com/docs/templating/filters#kebab) instead of `url_encode`, like this: `{jobTitle|kebab}`

> **Comments:**
> **username_0**: Thank you Megatrond, I didn't know about this one, I'll give it a go now!  
> **username_0**: Yes, this worked a treat. Much cleaner code! Many thanks.      jobs/{jobTitle|kebab}-{jobCity|kebab}-{jobId|kebab}  

---

