Is there a twig filter to encode special characters like umlauts: {{ entry.title | filter }}

Datensätze & Karten

Which then should result in:


Basically what 'convertFilenamesToAscii' => true, does but as a filter.

I want to use this as a anchorlink later on so umlauts are not the best to have in anchor links.


I would use a combination of things:

  • Twig's replace filter to convert ä to ae etc.
  • Twig's convert_encoding filter to eliminate any remaining non-ascii characters
  • Craft's kebab filter to do its thing

and of course wrap the thing up in a macro

{% macro ascii_kebab(s) %}
  {{ s
    | replace({
        'ä': 'ae'
    | convert_encoding('ASCII', 'UTF-8')
    | kebab
{% endmacro %}
  • Thanks a lot for this! BTW: in craft 3 macros cannot contain dashes.
    – outline4
    Nov 10 '18 at 14:02
  • @outline4 whoops! removed the dash. Nov 11 '18 at 11:02

You can use Craft's |ascii Twig Filter, which was added in Craft 3.1.25, for this:

{{ entry.title|ascii }}

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.