﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
13379	New template filter suggestion (wrap)	david.arakelian@…	nobody	"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>"" }}
}}}

"		closed	Template system	dev		wontfix	wrap, template filter		Unreviewed	0	0	0	0	0	0
