G'day … I've been trying to include different Matrix fields in Javascript code: for example the caption and alt text from images. My methods for trying to make this text 'safe' to include seem a bit convoluted, and I wondered if anyone had any suggestions…
I tried using the ^replace modifier to get rid of newlines, but couldn't get it to work. Is it possible to replace special characters such as newlines?
I tried using ^nl2br but that keeps the newlines in while inserting the <br /> tags. (See http://bugs.matrix.squiz.net/view_bug.php?bug_id=5002 )
This was my best attempt:
caption = '%asset_attribute_caption^trim^escapequotes^underscore^replace:_: %'
It converts whitespace (including newlines) to underscores, then replaces the underscores with spaces. This seems to work as long as there were no important underscores in the original string.
Is there a simpler way?