Hello,
We have a requirement where authors should be able to input javascript code from the dialog and it should render as is within HTL.
We provided a textarea for the same and in sightly have used ${properties.javascriptcode@ context='scriptString'} to render
This however upon render shows output similar to the following -
<script>\r\nfunction myFunction() {\r\n var str = \x22The best things in life are free\x22;\r\n var patt = new RegExp(\x22e\x22);\r\n var res = patt.test(str);\r\n document.getElementById(\x22demo\x22).innerHTML = res;\r\n}\r\n<\/script>
Is there a way to unescape these characters for scripts to render properly.Looking forward to your response.
Thanks.
Solved! Go to Solution.
Views
Replies
Total Likes
You can use JavaScript function unescape() for this.
Str="\r\nfunction myFunction() {\r\n var str = \x22The best things in life are free\x22;\r\n var patt = new RegExp(\x22e\x22);\r\n var res = patt.test(str);\r\n document.getElementById(\x22demo\x22).innerHTML = res;\r\n}\r\n"
document.write(unescape(str));
Output:- function myFunction() { var str = "The best things in life are free"; var patt = new RegExp("e"); var res = patt.test(str); document.getElementById("demo").innerHTML = res; }
Views
Replies
Total Likes
You can use JavaScript function unescape() for this.
Str="\r\nfunction myFunction() {\r\n var str = \x22The best things in life are free\x22;\r\n var patt = new RegExp(\x22e\x22);\r\n var res = patt.test(str);\r\n document.getElementById(\x22demo\x22).innerHTML = res;\r\n}\r\n"
document.write(unescape(str));
Output:- function myFunction() { var str = "The best things in life are free"; var patt = new RegExp("e"); var res = patt.test(str); document.getElementById("demo").innerHTML = res; }
Views
Replies
Total Likes
That is an unusual requirement. Most of the time when JS is used with HTL component - the JS is created as part of the HTL component - as discussed here: Adobe Experience Manager Help | Creating an Adobe Experience Manager HTML Template Language componen...
(that is the 1st time I have heard of letting an author enter JS logic via a component dialog)
Views
Replies
Total Likes
Thankyou this helped.I have later used eval for evaluating and outputting the code updated there.
Views
Replies
Total Likes
smacdonald2008 : Agree.Its not recommended for authors to have this option.
Views
Replies
Total Likes
Views
Likes
Replies