Created
June 23, 2009 21:09
-
-
Save dryan/134847 to your computer and use it in GitHub Desktop.
Django templatetag for giving an input a class matching its type attr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.template import Library | |
| from django.conf import settings | |
| from django.template.defaultfilters import slugify | |
| register = Library() | |
| def input_class(input): | |
| try: | |
| slug = slugify(input.field.widget.__class__.__name__.replace('Input','')) | |
| if hasattr(input.field.widget, 'attrs') and 'class' in input.field.widget.attrs: | |
| slug += " " + input.field.widget.attrs['class'] | |
| return slug | |
| except Exception, e: | |
| return "" | |
| register.filter(input_class) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment