Twig
Twig copied to clipboard
Twig strings don't support PHP string escape sequences
I'm trying to insert a non-breaking space (NBSP) into a string in a Twig template, but all the ways I've thought to try haven't worked.
And upon further research it seems that Twig strings do not support the full gamut of escape sequences that PHP supports: https://www.php.net/manual/en/language.types.string.php
For example, this code:
{{ "\240\xA0\u{00A0} " }}
produces:
��u{00A0}
instead of:
I've elaborated some here: https://twigfiddle.com/q41fr9
As such, I have two questions: (1) Is this expected behavior? (2) Is there a way to do what I want to do that I'm missing?
Twig relies on stripcslashes which indeed does not cover the PHP escape sequences but only the C ones.