title: Custom jinja2 filter for iterator
body: <p>How do I most efficiently write a custom filter for Jinja2 that applies to an iterable like the built-in 'sort' filter, for use in a for loop in the template?</p>
  
  <p>For example:</p>
  
  <pre><code>{% for item in iterable|customsort(somearg) %}
  ...
  {% endfor %}
  </code></pre>
  
  <p>See <a href="http://jinja.pocoo.org/docs/api/#writing-filters" rel="noreferrer">http://jinja.pocoo.org/docs/api/#writing-filters</a> for general documentation</p>