Skip to content

Instantly share code, notes, and snippets.

@mitsuhiko
Created September 20, 2013 00:28
Show Gist options
  • Save mitsuhiko/6631789 to your computer and use it in GitHub Desktop.
Save mitsuhiko/6631789 to your computer and use it in GitHub Desktop.
{% set has_changed = make_has_changed() %}
{% for item in foo %}
{% if has_changed(item.date.year, item.date.month) %}
<h1>{{ item.date.year }} {{ item.date.month }}</h1>
{% endif %}
...
{% endfor %}
class HasChangedHelper(object):
def __init__(self):
self.state = None
def __call__(self, *new_state):
if self.state != new_state:
self.state = new_state
return True
return False
jinja_env.globals['make_has_changed'] = HasChangedHelper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment