<p>You can do this with the Luke Holder's <a href="https://github.com/lukeholder/craft-inflect" rel="nofollow">Inflect plugin</a>. Which method to use would depend on how you want the resulting text to look. I'd use <code>{{ myTextField|slugify }}</code> to get a string that looks like this "this-is-my-class", since I only use lowercase and hyphenate class/id names.</p>

CC BY-SA 3.0
2014-10-13T13:03:49.643Z
Looks like I was a little to quick when hitting the accepted answer button :) The Inflect plugin doesn't seem to convert characters in the string to class/id safe characters. Any advice on this?
Alf Vestre
CC BY-SA 3.0
2014-10-13T13:46:17.707Z
What characters isn't converted?
André Elvan
CC BY-SA 3.0
2014-10-14T06:36:30.343Z
From my tests it seems like only spaces and casing are affected by the Inflect plugin. No other characters are converted, I have tested these so far: æøåüëäéóú
Alf Vestre
CC BY-SA 3.0
2014-10-08T13:30:17.203Z
2014-10-08T13:30:17.203Z
André Elvan
<p>Does anyone know if it is possible to apply a Twig filter or use escaping to convert a Craft textfield into a html class/id safe string?</p>

<templating><filter><escaping>
Convert textfield to be used in html class or id?
# Convert textfield to be used in html class or id?

(Asked by: username_0 on 2014-10-08)

Does anyone know if it is possible to apply a Twig filter or use escaping to convert a Craft textfield into a html class/id safe string?

**Tags:** templating, filter, escaping


---

## 1 answers

### Answer by username_1 on 2014-10-08. Score: 1 | Accepted answer

You can do this with the Luke Holder's [Inflect plugin](https://github.com/lukeholder/craft-inflect). Which method to use would depend on how you want the resulting text to look. I'd use `{{ myTextField|slugify }}` to get a string that looks like this "this-is-my-class", since I only use lowercase and hyphenate class/id names.

> **Comments:**
> **username_0**: Looks like I was a little to quick when hitting the accepted answer button :) The Inflect plugin doesn't seem to convert characters in the string to class/id safe characters. Any advice on this?  
> **username_1**: What characters isn't converted?  
> **username_0**: From my tests it seems like only spaces and casing are affected by the Inflect plugin. No other characters are converted, I have tested these so far: æøåüëäéóú  

---

