title: What is the proper syntax for using a django template variable as a jade href id reference?
body: <p>I am trying to generate a navigation table using a django template <code>for</code> loop.  The href target includes a django variable.  The django template is written in jade format.</p>
  
  <p>If i were using HTML format in the django template, I would use:</p>
  
  <pre><code>&lt;a href="#{{group.name}}"&gt; {{group.name}} &lt;/a&gt;
  </code></pre>
  
  <p>But I can't find the correct syntax using jade format.</p>
  
  <p>What I have is:</p>
  
  <pre><code>table.generic
    tbody
      tr
        th Jump to a Group
      {% for group in groups %}
      tr
        td
          a(href!='#{{group.name}}') {{group.name}}
      {% endfor %}
  </code></pre>
  
  <p>But the anchors are rendered in HTML as:</p>
  
  <pre><code>&lt;a +{group.name.__str__()+'}'="" href=""&gt;Registration&lt;/a&gt;
  </code></pre>
  
  <p>"Registration" is a value for group.name.</p>
  
  <p>Removing the <code>!</code> causes a django render error.</p>
  
  <p>I tried to insert a backslash: <code>a(href!='#\{{group.name}}') {{group.name}}</code>, but this renders with the backslash intact as:</p>
  
  <pre><code>&lt;a href="#\Registration"&gt;Registration&lt;/a&gt;
  </code></pre>
  
  <p>Suggestions?</p>
  
  <p><strong>Edit:</strong> As a terrible work-around, I have added a "pound" method to return the group name with a <code>#</code> prefix:</p>
  
  <pre><code>def pound(self): 
      return unicode("#" + self.name)
  </code></pre>
  
  <p>Now I can reference {{group.pound}} in the jade template:</p>
  
  <pre><code>a(href!='{{group.pound}}') {{group.name}}
  </code></pre>
  
  <p>Maybe a better method name would be group.name_as_id_tag .... </p>
  
  <hr>
  
  <h2>RESOLVED: Format the django template variable as a jade variable</h2>
  
  <p>Based on the last suggestion from @user1737909, I extended the suggestion to try:</p>
  
  <pre><code>a(href='##{group.name}') {{group.name}}
  </code></pre>
  
  <p>The key is to format the double-curly django variable <code>{{}}</code> as pound-single-curly jade variable <code>#{}</code>.  Do not include the <code>!</code> before the <code>=</code> sign so the variable <em>is</em> evaluated by jade which will insert the value it gets from django.</p>
  
  <p>I wish I could find a link to a coding style reference page to include here.  But if I had one, I would not have asked this question in the first place.</p>