Conditional template parsing block

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from django.conf import settings
from django.template import Node, Library
from django.template.defaulttags import CommentNode, AutoEscapeControlNode

register = Library()

def BoringNode(Node):
	def __init__(self, nodelist):
		self.nodelist = nodelist

	def render(self, context):
		return self.nodelist.render(context)

@register.tag
def gisblock(parser, token):
	if not settings.BRIGHTWAY_GIS_SUPPORT:
		parser.skip_past('endgisblock')
		return CommentNode()

	nodelist = parser.parse(('endgisblock',))
	parser.delete_first_token()

	# HACK!!! why doesn't BoringNode work? I always get strange
	# errors ('NoneType' has no attribute 'source')
	return AutoEscapeControlNode(True, nodelist)
	#return BoringNode(nodelist)

More like this

  1. PyIf Template Tag (Conditional Tag) by nstrite 5 years, 2 months ago
  2. template tag for highlighting currently active page by adunar 3 years, 7 months ago
  3. GeoDjango maps in admin TabularInlines by alanB 1 year, 7 months ago
  4. testdata tag for templates by showell 3 years ago
  5. fancy_if by Scanner 5 years, 1 month ago

Comments

(Forgotten your password?)