#13379: New template filter suggestion (wrap)
----------------------------------------------+-----------------------------
Reporter: [email protected] | Owner: nobody
Status: new | Milestone: 1.2
Component: Template system | Version: SVN
Keywords: wrap, template filter | Stage: Unreviewed
Has_patch: 0 |
----------------------------------------------+-----------------------------
We came across a use case today for wrapping variables in styles If they
are not None/Empty/False...[[BR]]
E.g. If a variable exists add a break tag after it or if a value exists
then wrap it in a <p></p> tag.
So we wrote a simple template tag that might be of interest to the
community.
Template tag:
{{{
from django import template
from django.template.defaultfilters import stringfilter
from django.utils.safestring import mark_safe
register = template.Library()
@register.filter
@stringfilter
def wrap(value, arg):
if value and value != '':
return mark_safe(arg % value) # decision needed with |safe
return value
}}}
Usage:
{{{
{{ var|wrap:"%s<br />" }} or
{{ var|wrap:"<p>%s</p>" }}
}}}
--
Ticket URL: <http://code.djangoproject.com/ticket/13379>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.