Skip to content

Commit

Permalink
don't render templates if the template tag is blank
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrDlouhy committed Nov 19, 2020
1 parent f5fdf74 commit e2784c5
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions scribbler/templatetags/scribbler_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,7 @@ def render(self, context):
else:
scribble_template = template.Template(self.raw)
scribble_context = build_scribble_context(scribble)
content = scribble_template.render(scribble_context, request)
wrapper_template = template.loader.get_template('scribbler/scribble-wrapper.html')
context['scribble'] = scribble
context['rendered_scribble'] = content
user = context.get('user', None)
show_controls = False
can_edit = False
Expand All @@ -92,8 +89,13 @@ def render(self, context):
context['can_edit_scribble'] = can_edit
context['can_delete_scribble'] = can_delete
context['raw_content'] = self.raw
if not bool(scribble.content.strip()) and not (can_edit or can_add):
return "<div></div>" # Don't bother to render blank scribble
content = scribble_template.render(scribble_context, request)
context['rendered_scribble'] = content
# render() takes a dict, so we have to extract the context dict from the object
context_data = context.dicts[-1]
wrapper_template = template.loader.get_template('scribbler/scribble-wrapper.html')
return wrapper_template.render(context_data, request)


Expand Down

0 comments on commit e2784c5

Please sign in to comment.