Commit cd652918 authored by Kroustouris Stauros's avatar Kroustouris Stauros

include maybe

parent dcfcddae
<iframe id='logos' scrolling="no" marginheight="0" marginwidth="0" src="https://dido.grnet.gr/logos/index.html" frameborder="0" height="60" width="500" align="middle"></iframe>
<style type="text/css" scoped>
iframe#logos {
width: 100%;
height: 60px;
}
@media screen and (max-width: 480px) {
iframe#logos {
height: 120px;
}
}
</style>
......@@ -16,7 +16,7 @@
Powered by <a href="http://djnro.grnet.gr/" target="_blank">DjNRO</a> v{{VERSION}}
{% if "partial/bottom_iframe.html"|template_exists %}
<div class="">
{% include 'partial/bottom_iframe.html' %}
{% include_maybe 'partial/bottom_iframe.html' %}
</div>
{% endif %}
</div>
......
from django import template
from django.template.defaultfilters import stringfilter
from django.template.loader_tags import do_include
from django.template.defaulttags import CommentNode
register = template.Library()
......@@ -13,3 +15,29 @@ def template_exists(value):
return True
except template.TemplateDoesNotExist:
return False
@register.tag('include_maybe')
def do_include_maybe(parser, token):
"Source: http://stackoverflow.com/a/18951166/15690"
bits = token.split_contents()
if len(bits) < 2:
raise template.TemplateSyntaxError(
"%r tag takes at least one argument: "
"the name of the template to be included." % bits[0])
try:
silent_node = do_include(parser, token)
except template.TemplateDoesNotExist:
# Django < 1.7
return CommentNode()
_orig_render = silent_node.render
def wrapped_render(*args, **kwargs):
try:
return _orig_render(*args, **kwargs)
except template.TemplateDoesNotExist:
return CommentNode()
silent_node.render = wrapped_render
return silent_node
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment