Skip to content

Instantly share code, notes, and snippets.

@adamn
Created September 15, 2010 18:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamn/581230 to your computer and use it in GitHub Desktop.
Save adamn/581230 to your computer and use it in GitHub Desktop.
from django import template
from django.template.defaultfilters import stringfilter
register = template.Library()
@register.filter(name='prepend')
@stringfilter
def prepend(value, arg):
"""
Prepends value with arg if value exists, else returns ''
"""
return '%s%s' % (arg, value) if value else ''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment