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:
parent
e32af567ef
commit
09f3f51c77
0
ietf/utils/templatetags/__init__.py
Normal file
0
ietf/utils/templatetags/__init__.py
Normal file
27
ietf/utils/templatetags/origin.py
Normal file
27
ietf/utils/templatetags/origin.py
Normal 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()
|
Loading…
Reference in a new issue