title: Nested Jinja2 for loops
body: <p>I'm passing 2 variables (3 including a simple one) to some Jinja from a python script.</p>
  
  <p>On certain runs I want to generate a list with links.</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
      &lt;h1&gt;{{ title }}&lt;/h1&gt;
      &lt;table&gt;
  
          {% if packageURLs is defined %}
              {% for x in packageURLs: %}
                  &lt;a href="{{ x }}"&gt;
              {% endfor %}
  
  
              {% for i in packagesList: %}
                  &lt;tr&gt;&lt;td&gt;{{ i }}&lt;/td&gt;&lt;/tr&gt;
  
              {% endfor %}
  
  
          {" else "}
  
  
              {% for i in packagesList: %}
                  &lt;tr&gt;&lt;td&gt;{{ i }}&lt;/td&gt;&lt;/tr&gt;
  
              {% endfor %}
          {% endif %}
  
          &lt;/a&gt;
      &lt;/table&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p></p>
  
  <p>for each 'packageURLs' I want to add a  tag then some table tags for 'packages' List. What's happening though is its generating HTML but completing each individual for loop first. So I end up with half a page full of links then another with table rows. How can I have it iterate through both initially? </p>