Commit c5a8714e authored by Zenon Mousmoulas's avatar Zenon Mousmoulas

Merge template tags include_maybe, template_exists in one file: template_maybe.py

parent f5557fe8
from django import template
from django.template.defaultfilters import stringfilter
register = template.Library()
@register.filter
@stringfilter
def template_exists(value):
try:
template.loader.get_template(value)
return True
except template.TemplateDoesNotExist:
return False
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()
@register.filter
@stringfilter
def template_exists(value):
try:
template.loader.get_template(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
......
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