Do statement not working in jinja
<p>I'm altering an existing web interface to view ROBOT doc libraries, which uses a mixture of jinja (Python inside HTML) and HTML. I have never worked with jinja or HTML before and am having issues getting even a simple test case to work. When the browser loads the docs, I want our project's directory structure for the docs to be preserved to make finding things easier, and so I want to use jinja to create the dir structure. Here is a snippet of the code I'm working with:</p>

<pre><code>{% extends "base.html" %}
{% block body %}
&lt;div class="well" id="left"&gt;
  &lt;ul class="list-group list-unstyled"&gt;
    {% set collection_list = [] %}
    {% for collection in data.hierarchy %}
      {% if collection.collection_id|string == data.collection_id|string %}
          {% do collection_list.append(collection.path) %}
      {% else %}
        {% for link in collection.path_chain %}
          &lt;li&gt;
          &lt;label class="tree-toggler nav-header"
                 title="file path: {{collection.path}}"&gt;{{link}}&lt;/label&gt;
          &lt;ul class="list-group  tree collapse"
              id={{link}}&gt;
              &lt;/ul&gt;
        {% endfor %}
          &lt;/li&gt;
      {% endif %}
</code></pre>

<p>...there's more after that, but this is where I hit the error. It sets the collection_list var fine, and the if statements work, but when it goes to execute the 'do' statement it fails with:</p>

<p><strong>TemplateSyntaxError: Encountered unknown tag 'do'. Jinja was looking for the following tags: 'elif' or 'else' or 'endif'. The innermost block that needs to be closed is 'if'.</strong></p>

<p>I don't believe this is an unclosed loop or something because if I replace the do statement with a simple test print statement, it works. Does anyone know what I'm doing wrong?</p>

<p>From the <a href="http://jinja.pocoo.org/docs/dev/templates/#expression-statement" rel="nofollow">template documentation</a>:</p>

<blockquote>
  <h3>Expression Statement</h3>
  
  <p>If the expression-statement extension is loaded, a tag called <code>do</code> is available that works exactly like the regular variable expression (<code>{{ ... }}</code>); except it doesnât print anything. This can be used to modify lists:</p>

<pre><code>{% do navigation.append('a string') %}
</code></pre>
</blockquote>

<p>You need to enable the <a href="http://jinja.pocoo.org/docs/dev/extensions/#expression-statement" rel="nofollow">Expression statement extension</a> for this to work.</p>

<p>You didn't show how you load the Jinja2 environment, but loading extensions takes place via the <code>extensions</code> argument to the <a href="http://jinja.pocoo.org/docs/dev/api/#jinja2.Environment" rel="nofollow"><code>Environment()</code> class</a>:</p>

<pre><code>jinja_env = Environment(extensions=['jinja2.ext.do'])
</code></pre>

python html jinja2