# safeJS being ignored

**URL:** <https://discourse.gohugo.io/t/safejs-being-ignored/2433>\
**Category:** support\
**Created:** [January 11, 2016, 10:36pm UTC](https://discourse.gohugo.io/t/safejs-being-ignored/2433 "2016-01-11T22:36:50Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raymond\_Camden](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/raymond_camden/32/1076_2.png) [@Raymond\_Camden](https://discourse.gohugo.io/u/Raymond_Camden)\
**Post date:** [January 11, 2016, 10:36pm UTC](https://discourse.gohugo.io/t/safejs-being-ignored/2433/1 "2016-01-11T22:36:50Z")

</div>

I’m building my own disqus partial (I’ve got some weird requirements for my site so I can’t use the built in support) and am running into issues trying to build a URL string. This is what I have:

`this.page.url = 'http://www.raymondcamden.com{{ .URL | safeJS }}';`

I am using safeJS because I do not want the forward slashes in the value escaped. However, I’m still seeing this in source:

`this.page.url = 'http://www.raymondcamden.com\/2015\/12\/28\/favorite-media-in-2015';`

Any idea why?

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [January 11, 2016, 10:53pm UTC](https://discourse.gohugo.io/t/safejs-being-ignored/2433/2 "2016-01-11T22:53:25Z")

</div>

Is it inside script tags? You could try `safeURL`

---

<div class="post-metadata">

**Author:** ![Raymond\_Camden](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/raymond_camden/32/1076_2.png) [@Raymond\_Camden](https://discourse.gohugo.io/u/Raymond_Camden)\
**Post date:** [January 11, 2016, 11:06pm UTC](https://discourse.gohugo.io/t/safejs-being-ignored/2433/3 "2016-01-11T23:06:17Z")

</div>

No go. Still modifies it.

---

<div class="post-metadata">

**Author:** ![Raymond\_Camden](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/raymond_camden/32/1076_2.png) [@Raymond\_Camden](https://discourse.gohugo.io/u/Raymond_Camden)\
**Post date:** [January 11, 2016, 11:08pm UTC](https://discourse.gohugo.io/t/safejs-being-ignored/2433/4 "2016-01-11T23:08:14Z")

</div>

And yes, it is inside script tags. Sorry I didn’t answer that question.

---

<div class="post-metadata">

**Author:** ![dimo414](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/dimo414/32/564_2.png) [@dimo414](https://discourse.gohugo.io/u/dimo414)\
**Post date:** [March 4, 2016, 4:55am UTC](https://discourse.gohugo.io/t/safejs-being-ignored/2433/5 "2016-03-04T04:55:31Z")

</div>

Strange as it sounds, try removing the quotes around the string. You should see in the rendered page the `.URL` value replaced with the URL, _quoted_. The Go template parser is context-aware, and so auto-quotes text inside JavaScript blocks. It took me a few attempts playing with the syntax to get what I wanted, but I wouldn’t have ever thought to remove the quotes had I not seen [this comment](https://discuss.gohugo.io/t/how-do-i-encode-a-url-in-frontmatter/2552/12?u=dimo414).

---

<div class="post-metadata">

**Author:** ![Raymond\_Camden](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/raymond_camden/32/1076_2.png) [@Raymond\_Camden](https://discourse.gohugo.io/u/Raymond_Camden)\
**Post date:** [March 4, 2016, 3:45pm UTC](https://discourse.gohugo.io/t/safejs-being-ignored/2433/6 "2016-03-04T15:45:28Z")

</div>

I did, but it didn’t work. Here is how I tested:

```
var raymond = http://www.raymondcamden.com{{ .URL | safeURL }}; 

```

And the output:

```
var raymond = http:
```

---

<div class="post-metadata">

**Author:** ![moorereason](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/moorereason/32/592_2.png) [@moorereason](https://discourse.gohugo.io/u/moorereason)\
**Post date:** [March 7, 2016, 4:55pm UTC](https://discourse.gohugo.io/t/safejs-being-ignored/2433/7 "2016-03-07T16:55:34Z")

</div>

I’ve found Go templates are very picky about context. You generally need to output the entire string, not part of it. Try something like this in a script context:

```auto
var raymond = {{ printf "http://www.raymondcamden.com%s" .URL | safeJS }}

```

---

<div class="post-metadata">

**Author:** ![Raymond\_Camden](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/raymond_camden/32/1076_2.png) [@Raymond\_Camden](https://discourse.gohugo.io/u/Raymond_Camden)\
**Post date:** [March 8, 2016, 9:34pm UTC](https://discourse.gohugo.io/t/safejs-being-ignored/2433/8 "2016-03-08T21:34:30Z")

</div>

Close - that output it perfectly, but without single quotes around it. So I got:

```
var raymond = http://www.raymondcamden.com/2016/03/07/how-i-added-search-to-my-static-blog;

```

(I added a ; to the end)

---

<div class="post-metadata">

**Author:** ![Raymond\_Camden](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/raymond_camden/32/1076_2.png) [@Raymond\_Camden](https://discourse.gohugo.io/u/Raymond_Camden)\
**Post date:** [March 8, 2016, 9:34pm UTC](https://discourse.gohugo.io/t/safejs-being-ignored/2433/9 "2016-03-08T21:34:56Z")

</div>

Oh, and if I add single quotes around it, it goes back to the broken, well, escaped, version.

---

<div class="post-metadata">

**Author:** ![Raymond\_Camden](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/raymond_camden/32/1076_2.png) [@Raymond\_Camden](https://discourse.gohugo.io/u/Raymond_Camden)\
**Post date:** [March 8, 2016, 9:36pm UTC](https://discourse.gohugo.io/t/safejs-being-ignored/2433/10 "2016-03-08T21:36:14Z")

</div>

Ok, so this worked:

```
var raymond = {{ printf "'http://www.raymondcamden.com%s'" .URL | safeJS }};

```

Holy smokes does that seem wrong. There really should be a way for me to say, “Don’t modify anything in this block - period”.

---

<div class="post-metadata">

**Author:** ![moorereason](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/moorereason/32/592_2.png) [@moorereason](https://discourse.gohugo.io/u/moorereason)\
**Post date:** [March 9, 2016, 1:00am UTC](https://discourse.gohugo.io/t/safejs-being-ignored/2433/11 "2016-03-09T01:00:43Z")

</div>

That’s probably my fault. Try removing `safeJS`, and it should quote the string for you.
