Suggestion #28437

Viewhelper to escape quotes and remove newlines for Javascript

Added by Marco Huber over 8 years ago. Updated over 8 years ago.

Status:
New
Priority:
Should have
Assignee:
-
Start date:
2011-07-24
Due date:
% Done:

0%

Has patch:
Tags:

Description

Removes linebreaks and escapes ' (or ").
By default ' is replaced by \', but you can set the argument
quote to say that all " should be replaced by \".

As soon as I'm allowed to I will commit it to the repository.

= Examples =

<script type="text/javascript"> var myString = '<f:jsString>this is a string<br /> perhaps it has a linebreak<br /> or it has a ' and would break the Javascript!</f:jsString>'; </script>
<output>
<script type="text/javascript">
var myString = 'this is a string<br />perhaps it has a linebreak<br />or it has a \' and would break the Javascript!';
</script>
</output> <script type="text/javascript"> var myString = "<f:jsString quote='\"'>this is a string and the " should be escaped</f:jsString>"; </script>
<output>
<script type="text/javascript">
var myString = "this is a string and the \" should be escaped";
</script>
</output>

JsStringViewHelper.zip (5.54 KB) Marco Huber, 2011-07-24 23:31

History

#1 Updated by Bastian Waidelich over 8 years ago

  • Tracker changed from Feature to Suggestion

Also available in: Atom PDF