<p>I would use a combination of things:</p>

<ul>
<li>Twig's <a href="https://twig.symfony.com/doc/2.x/filters/replace.html" rel="nofollow noreferrer">replace</a> filter to convert <code>ä</code> to <code>ae</code> etc.</li>
<li>Twig's <a href="https://twig.symfony.com/doc/2.x/filters/convert_encoding.html" rel="nofollow noreferrer">convert_encoding</a> filter to eliminate any remaining non-ascii characters</li>
<li>Craft's <a href="https://craftcms.com/docs/templating/filters#kebab" rel="nofollow noreferrer">kebab</a> filter to do its thing</li>
</ul>

<p>and of course wrap the thing up in a macro</p>

<pre><code>{% macro ascii_kebab(s) %}
  {{ s
    | replace({
        'ä': 'ae'
      })
    | convert_encoding('ASCII', 'UTF-8')
    | kebab
  }}
{% endmacro %}
</code></pre>

CC BY-SA 4.0
2018-11-10T14:02:53.833Z
Thanks a lot for this! BTW: in craft 3 macros cannot contain dashes.
outline4
CC BY-SA 4.0
2018-11-11T11:02:48.653Z
@outline4 whoops! removed the dash.
Marion Newlevant
CC BY-SA 4.0
2017-10-10T12:14:42.637Z
2018-11-11T11:02:08.567Z
2018-11-11T11:02:08.567Z
Marion Newlevant
<p>You can use Craft's <code>|ascii</code> Twig Filter, <a href="https://github.com/craftcms/cms/blob/master/CHANGELOG-v3.md#3125---2019-04-30" rel="nofollow noreferrer">which was added in Craft 3.1.25</a>, for this:</p>

<pre><code>{{ entry.title|ascii }}
</code></pre>

CC BY-SA 4.0
2019-05-02T09:15:24.363Z
2019-05-08T09:13:54.117Z
2019-05-08T09:13:54.117Z
Bramus
<p>Is there a twig filter to encode special characters like umlauts:
<code>{{ entry.title | filter }}</code></p>

<blockquote>
  <p>Datensätze &amp; Karten</p>
</blockquote>

<p>Which then should result in:</p>

<blockquote>
  <p>datensaetze-karten</p>
</blockquote>

<p>Basically what <code>'convertFilenamesToAscii' =&gt; true,</code> <a href="https://craftcms.com/docs/config-settings#convertFilenamesToAscii" rel="nofollow noreferrer">does</a> but as a filter.</p>

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

<filter><escaping>
Convert characters to Ascii
# Convert characters to Ascii

(Asked by: username_0 on 2017-10-10)

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](https://craftcms.com/docs/config-settings#convertFilenamesToAscii) 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.

**Tags:** filter, escaping

---

## 2 answers

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

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 %}

> **Comments:**
> **username_2**: Thanks a lot for this! BTW: in craft 3 macros cannot contain dashes.  
> **username_1**: @outline4 whoops! removed the dash.  

---

### Answer by username_3 on 2019-05-02. Score: 1

You can use Craft's |ascii Twig Filter, which was added in Craft 3.1.25, for this:
{{ entry.title|ascii }}


---

