Login

split filter

Author:
Ciantic
Posted:
May 2, 2007
Language:
Python
Version:
.96
Tags:
filter split
Score:
2 (after 2 ratings)

Usage (in template):

<img src="{{ MEDIA_URL }}2007/images/{% filter split:","|random %}theimage1.jpg,something2.jpg,thirdisthecharm.jpg{% endfilter %}" />

I decided to make it simple, because one template creator wanted to add random images to different places of templates. Creating something huge, like external image filename parsing was not necessary in this case.

1
2
3
4
5
6
from django import template
register = template.Library()

@register.filter
def split(str,splitter):
    return str.split(splitter)

More like this

  1. Filter to resize a ImageField on demand by michelts 8 years, 3 months ago
  2. Random-image template tag by pbx 8 years, 4 months ago
  3. Split a string to a list and add to select options by xuqingkuang 6 years, 3 months ago
  4. Simple random file CAPTCHA by jeverling 3 years, 4 months ago
  5. Support for {% macro %} tags in templates, version 2 by mludvig 7 years, 11 months ago

Comments

Please login first before commenting.