mstdmstd Posted January 17, 2021 Share Posted January 17, 2021 Hello, In my Laravel 8 / jQuery 3.5.1 app I need to put string text in javascript like : L.marker([{{$adLocation->lat}}, {{ $adLocation->lng }}]).addTo(locationMap) .bindPopup("<b>Add Location!</b><br />"+'{!! crlf($adLocation->content) !!}'+".").openPopup(); I try to replace crlf characters with method like function crlf(string $s) : string { return str_replace( array("\r\n", "\r", "\n"), "<br />", $s); // 2 lines below does not work too // return preg_replace('/\<br(\s*)?\/?\>/i', "\n", $s); // return nl2br($s); } But anyway I got error : edit:539 Uncaught SyntaxError: Invalid or unexpected token and I see in browser : https://prnt.sc/wtpnri and https://prnt.sc/wtq78t Which way is valid ? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/312014-putting-put-string-text-in-javascript-raise-syntax-error/ Share on other sites More sharing options...
requinix Posted January 17, 2021 Share Posted January 17, 2021 Normal Javascript strings do not work across multiple lines. If you're putting a value into Javascript then use @json instead. You should basically never ever use {!! for anything. Quote Link to comment https://forums.phpfreaks.com/topic/312014-putting-put-string-text-in-javascript-raise-syntax-error/#findComment-1583822 Share on other sites More sharing options...
mstdmstd Posted January 18, 2021 Author Share Posted January 18, 2021 Well, if to work the line on server, which methods have I to use? Quote Link to comment https://forums.phpfreaks.com/topic/312014-putting-put-string-text-in-javascript-raise-syntax-error/#findComment-1583849 Share on other sites More sharing options...
requinix Posted January 18, 2021 Share Posted January 18, 2021 I can't tell what you were trying to ask, but I think the answer is still what I said before. Quote Link to comment https://forums.phpfreaks.com/topic/312014-putting-put-string-text-in-javascript-raise-syntax-error/#findComment-1583850 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.