2

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"?

0

1 Answer 1

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 in Twig. It uses a function called mb-convert-encoding.

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.

4
  • 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
    Commented Jun 2, 2016 at 15:32
  • Just a thought - do you need the character to be replaced or could you remove it? Just found this answer that removes special characters: stackoverflow.com/a/8171868 Commented Jun 2, 2016 at 15:35
  • 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
    Commented Jun 3, 2016 at 11:00
  • did you ever find a solution?
    – outline4
    Commented Nov 10, 2018 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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