title: if else branching in jinja2
body: <p>what sort of conditions can we use for branching in jinja2? I mean can we use python like statements. For example, I want to check the length of the caption. If bigger than 60 characters, I want to limit it to 60 characters and put "..." Right now, I'm doing something like this but it doesn't work. error.log reports that len function is undefined.</p>
  
  <pre><code>template = Template('''
      &lt;!DOCTYPE html&gt;
              &lt;head&gt;
                      &lt;title&gt;search results&lt;/title&gt;
                      &lt;link rel="stylesheet" href="static/results.css"&gt;
              &lt;/head&gt;
              &lt;body&gt;
                      {% for item in items %}
                              {% if len(item[0]) &lt; 60 %}
                                      &lt;p&gt;&lt;a href="{{ item[1] }}"&gt;{{item[0]}}&lt;/a&gt;&lt;/p&gt;
                              {% else %}
                                      &lt;p&gt;&lt;a href="{{ item[1] }}"&gt;{{item[0][40:]}}...&lt;/a&gt;&lt;/p&gt;
                              {% endif %}
                      {% endfor %}
              &lt;/body&gt;
      &lt;/html&gt;''')
  
  ## somewhere later in the code...
  
  template.render(items=links).encode('utf-8')
  </code></pre>