Skip to content

Instantly share code, notes, and snippets.

@d6veteran
Created January 11, 2011 16:17
Show Gist options
  • Save d6veteran/774644 to your computer and use it in GitHub Desktop.
Save d6veteran/774644 to your computer and use it in GitHub Desktop.
Custom filter for Webapp templates: match item to items in List
from google.appengine.ext.webapp import template
from django import template as django_template
def in_list(value, arg):
"""
Given an item and a list, check if the item is in the list.
Usage:
{% if item|in_list:list %}
in list
{% else %}
not in list
{% endif %}
"""
return value in arg
register = template.create_template_register()
ifinlist = register.filter(in_list)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment