Added support for an 'origin' template tag which will insert the name of the template file (within a html comment) into the page content when TEMPLATE_DEBUG is True; with the purpose of more easily being able to identify the templates from which page content comes.

- Legacy-Id: 9550
This commit is contained in:
Henrik Levkowetz 2015-04-24 20:38:36 +00:00
parent e32af567ef
commit 09f3f51c77
2 changed files with 27 additions and 0 deletions

View file

View file

@ -0,0 +1,27 @@
from django import template
import debug # pyflakes:ignore
register = template.Library()
class OriginNode(template.Node):
def __init__(self, origin=None):
# template file path if the template comes from a file:
self.origin = origin
def render(self, context):
if self.origin:
return "<!-- template: %s -->" % self.origin
else:
return ""
@register.tag
def origin(parser, token):
"""
Returns a node which renders the
"""
if hasattr(token, "source"):
origin, source = token.source
return OriginNode(origin=origin)
else:
return OriginNode()