# Conditional javascript partials

**URL:** <https://discourse.gohugo.io/t/conditional-javascript-partials/4694>\
**Category:** support\
**Created:** [November 29, 2016, 5:29pm UTC](https://discourse.gohugo.io/t/conditional-javascript-partials/4694 "2016-11-29T17:29:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![apfrod](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/apfrod/32/2310_2.png) [@apfrod](https://discourse.gohugo.io/u/apfrod)\
**Post date:** [November 29, 2016, 5:29pm UTC](https://discourse.gohugo.io/t/conditional-javascript-partials/4694/1 "2016-11-29T17:29:32Z")

</div>

I’m trying to make conditional javascript, so I can have a theme with features that that can turned on and off.

I tried putting the js file in partials and including it:

```
{{ if isset .Site.Params "coolfeature" }}
<script>
{{ partial "js/coolfeature.js" . }}
</script>
{{ end }}

```

…but the partial js file gets escaped like:

```
<script>
"$(function () {\n init();\n })\n"
</script>

```

How do I tell hugo to just include the js file without escaping it?

I found it works if I have surrounding my js, but then it’s not a js file and I don’t want multiple redundant tags. Ideally/ultimately I want to build a single js file.

---

<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:** [November 29, 2016, 6:14pm UTC](https://discourse.gohugo.io/t/conditional-javascript-partials/4694/2 "2016-11-29T18:14:28Z")

</div>

Try putting the `<script>` tags in the partial or using something like this:

```auto
{{ partial "js/foo.js" . | safeJS }}

```

Go templates are very picky about context.

---

<div class="post-metadata">

**Author:** ![apfrod](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/apfrod/32/2310_2.png) [@apfrod](https://discourse.gohugo.io/u/apfrod)\
**Post date:** [November 30, 2016, 9:57am UTC](https://discourse.gohugo.io/t/conditional-javascript-partials/4694/3 "2016-11-30T09:57:19Z")

</div>

@moorereason perfect thanks, ‘| safeJS’ is exactly what I needed

> **[Functions Quick Reference](https://gohugo.io/functions/)**
>
> Comprehensive list of Hugo templating functions, including basic and advanced usage examples.
