Skip to content

Commit 09f3f51

Browse files
committed
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
1 parent e32af56 commit 09f3f51

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

ietf/utils/templatetags/__init__.py

Whitespace-only changes.

ietf/utils/templatetags/origin.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from django import template
2+
import debug # pyflakes:ignore
3+
4+
register = template.Library()
5+
6+
7+
class OriginNode(template.Node):
8+
def __init__(self, origin=None):
9+
# template file path if the template comes from a file:
10+
self.origin = origin
11+
12+
def render(self, context):
13+
if self.origin:
14+
return "<!-- template: %s -->" % self.origin
15+
else:
16+
return ""
17+
18+
@register.tag
19+
def origin(parser, token):
20+
"""
21+
Returns a node which renders the
22+
"""
23+
if hasattr(token, "source"):
24+
origin, source = token.source
25+
return OriginNode(origin=origin)
26+
else:
27+
return OriginNode()

0 commit comments

Comments
 (0)