<p>My first idea would be to use the <code>url_encode</code> filter than would turn your special characters into a URL friendly format. I imagine these would also be Javascript friendly.</p>

<p>If you'd like to convert the characters to something like "ueber-uns" maybe take a look at the <code>convert_encoding</code> <a href="http://twig.sensiolabs.org/doc/filters/convert_encoding.html" rel="nofollow">filter</a> in Twig. It uses a function called <a href="http://php.net/manual/en/function.mb-convert-encoding.php" rel="nofollow">mb-convert-encoding</a>.</p>

<p>I tried to find what encoding you'd need to use to convert <code>Ü</code> to something javascript friendly but was only able print even more obscure characters.</p>

CC BY-SA 3.0
2016-06-02T15:32:11.290Z
Hi Luke, thanks I was aware of the filter but couldn't get it to work before because I couldn't figure out the correct to/from arguments.  I did a bunch of google searches but it doesn't output what I'm looking for, possible because "ue" is not really a character?  Dunno.  Encoding is always a bit of a mystery to me.
Ryan
CC BY-SA 3.0
2016-06-02T15:35:49.640Z
Just a thought - do you need the character to be replaced or could you remove it? Just found this answer that removes special characters: http://stackoverflow.com/a/8171868
Luke Pearce
CC BY-SA 3.0
2016-06-03T11:00:18.683Z
I suppose it could just be removed since it's an ID just in the code, but it would be nice to have it be replaced, since then I could technically use it in urls, etc.
Ryan
CC BY-SA 4.0
2018-11-10T13:40:48.260Z
did you ever find a solution?
outline4
CC BY-SA 3.0
2016-06-01T14:35:18.410Z
2016-06-01T14:35:18.410Z
Luke Pearce
<p>I have a text field that will accept some German text in it as a headline of a section. I'm using Craft's <code>|kebab</code> filter to turn that into a lowercase-with-dashes id that my navigation scrolls down to when its corresponding link is clicked.</p>

<p>However, when there's a word like "Über Uns", the umlaut Ü stays in the output like so: "über-uns" and this messes up my javascript so the scrolling doesn't work for that one item. Is there a filter or something to have it be output to "ueber-uns"?</p>

<templating><localization><filter>
Twig filter to convert special characters to URL friendly characters
# Twig filter to convert special characters to URL friendly characters

(Asked by: username_0 on 2016-06-01)

I have a text field that will accept some German text in it as a headline of a section. I'm using Craft's `|kebab` filter to turn that into a lowercase-with-dashes id that my navigation scrolls down to when its corresponding link is clicked.

However, when there's a word like "Über Uns", the umlaut Ü stays in the output like so: "über-uns" and this messes up my javascript so the scrolling doesn't work for that one item. Is there a filter or something to have it be output to "ueber-uns"?

**Tags:** templating, localization, filter

---

## 1 answers

### Answer by username_1 on 2016-06-01. Score: 2

My first idea would be to use the `url_encode` filter than would turn your special characters into a URL friendly format. I imagine these would also be Javascript friendly.

If you'd like to convert the characters to something like "ueber-uns" maybe take a look at the `convert_encoding` [filter](http://twig.sensiolabs.org/doc/filters/convert_encoding.html) in Twig. It uses a function called [mb-convert-encoding](http://php.net/manual/en/function.mb-convert-encoding.php).

I tried to find what encoding you'd need to use to convert `Ü` to something javascript friendly but was only able print even more obscure characters.

> **Comments:**
> **username_0**: Hi Luke, thanks I was aware of the filter but couldn't get it to work before because I couldn't figure out the correct to/from arguments.  I did a bunch of google searches but it doesn't output what I'm looking for, possible because "ue" is not really a character?  Dunno.  Encoding is always a bit of a mystery to me.  
> **username_1**: Just a thought - do you need the character to be replaced or could you remove it? Just found this answer that removes special characters: http://stackoverflow.com/a/8171868  
> **username_0**: I suppose it could just be removed since it's an ID just in the code, but it would be nice to have it be replaced, since then I could technically use it in urls, etc.  
> **username_2**: did you ever find a solution?  

---

