title: Go HTML templates: Can I stop the templates package inserting quotes around strings in scripts?
body: <p>All of my templates have a variable indicating the root url of their associated images. I want to output that root before the filename of the image in the body of the template, but when I do so, the templates package attempts to put quotes around it. Here's a minimal piece of code that shows my problem. IMG_ROOT is an interface in this example to better simulate the real code. The script type is text/template because its contents will be used in an underscore.js template. The type doesn't appear to matter to how it's output though.</p>
  
  <pre><code>package main
  
  import (
      "html/template"
      "os"
  )
  
  type Data struct {
      IMG_ROOT interface{}
  }
  
  const tmpl = `
  &lt;body&gt;
  &lt;script type="text/template"&gt;
      &lt;img src="{{.IMG_ROOT}}/file_name.jpg"&gt;&lt;/img&gt;
  &lt;/script&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>`</p>
  
  <pre><code>func main() {
      t, _ := template.New("").Parse(tmpl)
      t.Execute( os.Stdout, &amp;Data{ template.JSStr( "/path/to/file" ) } )
  }
  </code></pre>
  
  <p><a href="http://play.golang.org/p/wg9JK2w2lt" rel="nofollow">http://play.golang.org/p/wg9JK2w2lt</a></p>
  
  <p>If I write <code>&lt;img src="{{.IMG_ROOT}}/file_name.jpg"&gt;&lt;/img&gt;</code>, I get <code>"\/path\/to\/file/file_name.jpg"</code> which isn't valid.</p>
  
  <p>If I write <code>&lt;img src={{.IMG_ROOT}}/file_name.jpg&gt;&lt;/img&gt;</code>, I get <code>"/path/to/file/"file_name.jpg</code> which doesn't work either.</p>
  
  <p>Is there a workaround for this? I've tried using every 'safe' type from the templates package for the IMG_ROOT type, but haven't had any luck. I could just write a function that concatenates and returns the root and file, but it seems like there should be a simpler solution.</p>
  
  <p>Any ideas?</p>
  
  <p>Thanks!</p>