mirror of
https://github.com/ankitects/anki.git
synced 2025-09-23 08:22:24 -04:00
catch errors or missing fields when rendering template
This commit is contained in:
parent
9f6a21e0a7
commit
5c3a63d84b
1 changed files with 7 additions and 4 deletions
|
@ -110,9 +110,12 @@ class Template(object):
|
||||||
|
|
||||||
tag, tag_type, tag_name = match.group(0, 1, 2)
|
tag, tag_type, tag_name = match.group(0, 1, 2)
|
||||||
tag_name = tag_name.strip()
|
tag_name = tag_name.strip()
|
||||||
|
try:
|
||||||
func = modifiers[tag_type]
|
func = modifiers[tag_type]
|
||||||
replacement = func(self, tag_name, context)
|
replacement = func(self, tag_name, context)
|
||||||
template = template.replace(tag, replacement)
|
template = template.replace(tag, replacement)
|
||||||
|
except:
|
||||||
|
return "{{invalid template}}"
|
||||||
|
|
||||||
return template
|
return template
|
||||||
|
|
||||||
|
@ -133,7 +136,7 @@ class Template(object):
|
||||||
@modifier(None)
|
@modifier(None)
|
||||||
def render_unescaped(self, tag_name=None, context=None):
|
def render_unescaped(self, tag_name=None, context=None):
|
||||||
"""Render a tag without escaping it."""
|
"""Render a tag without escaping it."""
|
||||||
return unicode(get_or_attr(context, tag_name, ''))
|
return unicode(get_or_attr(context, tag_name, '{unknown field %s}' % tag_name))
|
||||||
|
|
||||||
# @modifier('>')
|
# @modifier('>')
|
||||||
# def render_partial(self, tag_name=None, context=None):
|
# def render_partial(self, tag_name=None, context=None):
|
||||||
|
|
Loading…
Reference in a new issue