Nammami_mar
Nammami_mar

Reputation: 13

How to disable escaping URL/string in an HTML template in a javascript block

I've tried to render a url as string, URL, JS and HTML. In all the cases this:

 <script>
  var someUrl = "{{ .myUrl }}";
 </script>

gets rendered to this value:

https:\/\/some_domain123.com\/path1\/path2\/path3

No matter what.

I want this:

https://some_domain123.com/path1/path2/path3

What actually works?

Upvotes: 0

Views: 1324

Answers (2)

blobdon
blobdon

Reputation: 1336

As @mkopriva commented, remove the double quotes around {{ .myURL }}, and it works as you want.

See it on the Playground

Upvotes: 1

P Varga
P Varga

Reputation: 20229

https:\/\/some_domain123.com\/path1\/path2\/path3 is the same as https://some_domain123.com/path1/path2/path3 in JavaScript.

So, it actually works.

Upvotes: 0

Related Questions