title: How to concatenate double curly brackets with variables in javascript
body: <p>I can't seem to figure this one out. I've got a Python/Django template which renders my variables using {{ variable }} and I'm trying to use Javascript on the HTML page to manipulate the variable when the user clicks a button.</p>
  
  <p>The problem I'm seeing is that Javascript seems to treat {{ differently, so that when it renders as HTML, it doesn't convert the variable (ie. it shows "+ id + " instead of 5 from the code below:</p>
  
  <pre><code>function changeDate()
    id = 5;
    html = "{{ variable[" + id + "] }}";
    document.getElementById('test').innerHTML = html;
  </code></pre>
  
  <p>I've tried escaping them like this: "{{" and that seems to work (ie. it converts 'id' to 5) but then Python doesn't interpret the string as a variable and it just displays the string on the page as {{ variable[5] }} rather than the real value of that variable.</p>
  
  <p>My <em>guess</em> is that this happens because Javascript is converting the DIV to the new text <em>after</em> the page is already rendered, so Python never has the chance to convert the variable when it first renders the page.</p>
  
  <p>So I think there are two possible solutions:</p>
  
  <ol>
  <li>Figure out a way to render the variable properly while leaving the {{ and }} in the string</li>
  </ol>
  
  <p>or</p>
  
  <ol>
  <li>Figure out how to get Python to interpret the string version of {{ variable[5] }} before it's ever displayed through Javascript.</li>
  </ol>
  
  <p>Any help is appreciated!</p>