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?
1 Answer
You can do this with the Luke Holder's Inflect plugin. 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.
-
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? Oct 13, 2014 at 13:03
-
-
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: æøåüëäéóú Oct 14, 2014 at 6:36