title: Javascript / Django Design Pattern
body: <p>I just have a question about how to achieve DRY with javascript that generates html on the fly.  I have a list of elements that are loaded dynamically and populated by the django template a la</p>
  
  <pre><code>{{ tag.title }}
  {% if request.user.is_authenticated %}
  &lt;a name="del-tag" data-id="{{ tag.id }}" class = "tag-x" title="Remove Tag" href="#"&gt;x&lt;/a&gt;
  {% endif %}
  </code></pre>
  
  <p>Now, I have some javascript that also loads new tags via ajax.  Here's the relevant portion:</p>
  
  <pre><code>var newTag = "&lt;span class = \"tag\"&gt;" + tagName + "&lt;a name=\"del-tag\" data-id=\"" + tag_id + "\"" +
                          "class = \"tag-x\" title=\"Remove Tag\" href=\"#\"&gt;x&lt;/a&gt;&lt;/span&gt;";
  $('#tags').append(newTag);
  </code></pre>
  
  <p>Can I avoid duplicating HTML in the javascript?</p>
  
  <p>Thanks.</p>