Skip to content

Fix missing html in context #68

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 29, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions djangocms_snippet/cms_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
from .models import SnippetPtr


CACHE_ENABLED = getattr(settings, 'DJANGOCMS_SNIPPET_CACHE', False)
CACHE_ENABLED = getattr(settings, "DJANGOCMS_SNIPPET_CACHE", False)


class SnippetPlugin(CMSPluginBase):
model = SnippetPtr
name = _('Snippet')
render_template = 'djangocms_snippet/snippet.html'
name = _("Snippet")
render_template = "djangocms_snippet/snippet.html"
text_enabled = True
text_editor_preview = False
cache = CACHE_ENABLED
Expand All @@ -26,25 +26,28 @@ def render(self, context, instance, placeholder):
try:
if instance.snippet.template:
context = context.flatten()
context.update({"html": mark_safe(instance.snippet.html)})
t = template.loader.get_template(instance.snippet.template)
content = t.render(context)
else:
# only html provided
t = template.Template(instance.snippet.html)
content = t.render(context)
except template.TemplateDoesNotExist:
content = _('Template %(template)s does not exist.') % {
'template': instance.snippet.template
content = _("Template %(template)s does not exist.") % {
"template": instance.snippet.template
}
except Exception as e:
content = escape(str(e))

context.update({
'placeholder': placeholder,
'object': instance,
'html': mark_safe(instance.snippet.html),
'content': content,
})
context.update(
{
"placeholder": placeholder,
"object": instance,
"html": mark_safe(instance.snippet.html),
"content": content,
}
)

return context

Expand Down