2

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

Datensätze & Karten

Which then should result in:

datensaetze-karten

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.

3

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 %}
| improve this answer | |
  • 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. – Marion Newlevant Nov 11 '18 at 11:02
1

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

{{ entry.title|ascii }}
| improve this answer | |

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.