2

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

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? – Alf Vestre Oct 13 '14 at 13:03
  • What characters isn't converted? – André Elvan Oct 13 '14 at 13:46
  • 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 Oct 14 '14 at 6:36

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.