Remove backslash using a variable

I want to use variable in this HTML block:

  <script type="application/ld+json">
    {
      "@context": "http://schema.org",
      "@type": "Product",
      "url": "{{ .Site.BaseURL }}",
      }
  </script>

However, it gets converted into this:

  <script type="application/ld+json">
    {
      "@context": "http://schema.org",
      "@type": "Product",
      "url": "http:\/\/localhost:1313\/",
      }
  </script>

How to remove unwanted backslashes? I tried {{ .Site.BaseURL | safeHTML }}, {{ replace .Site.BaseURL "\\/" "/" | safeHTML }}, but nothing worked

Not tested, but did you try piping to safeURL, htmlEscape, htmlUnescape functions? Sorry, I am not sure which of those might work but, one might work. Please try.

Thanks for the suggestion, but nothing worked.

Try:

"url": {{ .Site.BaseURL | safeHTML }}

Note the lack of "" around the curly braces.

3 Likes

Works, thanks!

1 Like