misc: add startswith templatetag (#25972)
This commit is contained in:
parent
8ce0d0b7de
commit
6dcb7fe9d7
|
@ -67,6 +67,12 @@ def test_template_templatetag():
|
|||
tmpl = Template('{% load i18n %}{% trans "hello" %}')
|
||||
assert tmpl.render() == 'hello'
|
||||
|
||||
def test_startswith_templatetag():
|
||||
tmpl = Template('{% if foo|startswith:"bar" %}hello{% endif %}')
|
||||
assert tmpl.render() == ''
|
||||
assert tmpl.render({'foo': 'bar-baz'}) == 'hello'
|
||||
assert tmpl.render({'foo': 'baz-bar'}) == ''
|
||||
|
||||
def test_template_encoding():
|
||||
# django
|
||||
tmpl = Template('{{ foo }} à vélo')
|
||||
|
|
|
@ -27,6 +27,10 @@ register = template.Library()
|
|||
def get(mapping, key):
|
||||
return mapping.get(key)
|
||||
|
||||
@register.filter
|
||||
def startswith(string, substring):
|
||||
return string and string.startswith(substring)
|
||||
|
||||
@register.filter
|
||||
def parse_date(date_string):
|
||||
try:
|
||||
|
|
Loading…
Reference in New Issue