Url forward slashes rendered quoted with backslash in javascript

I’m trying to create a url in a javascript section in a template on my site

let obj = {something: "{{ .Site.BaseURL }}img/icon.jpg"}

However in the rendered HTML the forward slashes get quoted with backslashes

http:\/\/example.com\/img/icon.jpg"

I have tried safeJS and jsonfiy (as mentioned in Solved: Url forward slashes rendered quoted with backslash) but they don’t seem to help. Why is this happening and how can I fix it?

<script>
  let obj = {something: {{ print site.BaseURL "img/icon.jpg" }}};
  console.log(obj.something); // http://localhost:1313/img/icon.jpg
</script>
1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.