ian@designkarma.co.uk

Ian Ebden · January 26, 2017


Looks like this article was written a while ago. Some of the ideas and/or techniques described may now be obselete.

Anyone that knows me knows that I’m currently completely in love with Craft CMS. My clients are too. It has all the flexibility that I need, and a smooth UX. Lately however, some clients have complained about odd formatting from ‘Rich Text’ fields brought about by the insertion of random non-breaking spaces. To be clear this isn’t a Craft bug, but a bug of the Redactor 2 WYSIWYG plugin used for Rich Text fields in Craft and many other CMS’s.

A fix is on the way, but in the meantime here’s a workaround I use in my templates using Twig’s replace filter:

{{ entry.body|replace({' ':' '})|raw }}

This will replace any offending non-breaking spaces with regular spaces, preserving normal formatting/rendering and semantics. It’s safe enough to leave in your templates, post any Redactor 2 fixes; and probably a good idea to use anyway in most instances because oftentimes content managers paste in content from programs like MS Word, which are guilty of sneaking in odd hidden characters.