This plugin was created to handle a conundrum I experienced working with designers that wanted to control the way text breaks on their layouts by using in the fields they are editing. To accommodate this I initially started filtering all field output with |raw which would render the as-is, however then single ampersands were being rendered as is, along with any other character that would otherwise be converted to an html entity. This plugin was created to combat that issue.
In a nutshell, it renders the text exactly as if you did {{ 'some text'|escape('html') }}
except it takes the
output from that and replaces   with regular old before returning the string to the view.
- Clone or download the zip.
- Place the "escapenonnbsp" folder inside your craft/plugins directory.
- Go to admin / settings / plugins.
- Install The plugin.
Inside your twig templates, just use it like any other filter
{% set test = "Some Raw text & characters but with non breaking space!"; %}
{{ test|escapeNonNbsp }}
The above will output:
Some Raw text & characters but with non breaking space!