Ticket #11717: patch-11717.diff

File patch-11717.diff, 1.1 KB (added by Alex Hayes, 15 years ago)

concat template tag.

  • django/template/defaultfilters.py

     
    862862        return u"Error in formatting: %s" % force_unicode(e, errors="replace")
    863863pprint.is_safe = True
    864864
     865def concat(value, arg, autoescape=None):
     866    """
     867    Concats value with arg.
     868   
     869    For example: {{ "this is"|concat:" a concatenated string." }}
     870    """
     871    value = force_unicode(value)
     872    if autoescape:
     873        from django.utils.html import conditional_escape
     874        value = conditional_escape(value)
     875    try:
     876        data = value + arg
     877    except AttributeError: # fail silently but nicely
     878        return value
     879    return mark_safe(data)
     880concat.is_safe = True
     881concat.needs_autoescape = True
     882
    865883# Syntax: register.filter(name of filter, callback)
    866884register.filter(add)
    867885register.filter(addslashes)
    868886register.filter(capfirst)
    869887register.filter(center)
     888register.filter(concat)
    870889register.filter(cut)
    871890register.filter(date)
    872891register.filter(default)
Back to Top