title: Mustache JS Templating - How do I embed a variable in a script tag string?
body: <p>I just started using Mustache and I like it so far, but this has me perplexed.</p>
  
  <p>I am using the GitHub gist API to pull down my gists, and part of what I want to do is include the embedding functionality into my page. The problem is Mustache seems to not want to have anything to do with my dynamic script tag.</p>
  
  <p>For example, this works fine:</p>
  
  <pre><code>&lt;div class="gist-detail"&gt;
      {{id}} &lt;!-- This produces a valid Gist ID --&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Additionally, this works perfect:</p>
  
  <pre><code>&lt;div class="gist-detail"&gt;
      &lt;script src='http://gist.github.com/1.js'&gt;&lt;/script&gt; &lt;!-- Produces the correct embed markup with Gist ID #1 --&gt;
  &lt;/div&gt;    
  </code></pre>
  
  <p>If I try to pull these <em>together</em>, something goes terribly wrong:</p>
  
  <pre><code>&lt;div class="gist-detail"&gt;
      &lt;script src='http://gist.github.com/{{id}}.js'&gt;&lt;/script&gt; &lt;!-- Blows up! --&gt;
  &lt;/div&gt;  
  </code></pre>
  
  <p>Chrome Inspector shows this:</p>
  
  <pre><code>GET https://gist.github.com/%7B%7Bid%7D%7D.js 404 (Not Found)
  </code></pre>
  
  <p>... which looks like to me something is weird with escapes or whatnot, so I switch over to the raw syntax:</p>
  
  <pre><code>&lt;div class="gist-detail"&gt;
      &lt;script src='http://gist.github.com/{{{id}}}.js'&gt;&lt;/script&gt; &lt;!-- Blows again! --&gt;
  &lt;/div&gt;  
  </code></pre>
  
  <p>And I get the same result in Inspector:</p>
  
  <pre><code>GET https://gist.github.com/%7B%7B%7Bid%7D%7D%7D.js 404 (Not Found)
  </code></pre>
  
  <p>How do I get the correct values to embed in the script tag?</p>
  
  <p>EDIT</p>
  
  <p>I am injecting the template as follows (in <code>document.ready</code>:</p>
  
  <pre><code>function LoadGists() {
      var gistApi = "https://api.github.com/users/&lt;myuser&gt;/gists";
  
      $.getJSON(gistApi, function (data) {
  
          var html, template;
          template = $('#mustache_gist').html();
  
          html = Mustache.to_html(template, {gists: data}).replace(/^\s*/mg, '');
          $('.gist').html(html);
      });
  
  }
  </code></pre>
  
  <p>The actually template is inside of a ruby partial, but it is wrapped in a div (not a script tag, is that a problem?) (that's hidden):</p>
  
  <pre><code>&lt;div id="mustache_gist" style="display: none;"&gt;
  
      {{#gists}}
          &lt;!-- see above --&gt;
      {{/gists}}
  
  &lt;/div&gt;
  </code></pre>
  
  <p>I assume a <code>div</code> is ok rather than a <code>script</code> because in either case, I'm pulling the <code>.html()</code>. Is this a bad assumption?</p>