You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
StackOverflow 2687173 has an interesting use case using a templatetag that we could easily support:
@register.tagdefinclude_block(parser, token):
try:
tag_name, include_file, block_name=token.split_contents()
exceptValueError:
raisetemplate.TemplateSyntaxError("%r tag requires a two arguments"% (token.contents.split()[0]))
#pass vars with stripped quotes returnIncludeBlockNode(include_file.replace('"', ''), block_name.replace('"', ''))
classIncludeBlockNode(template.Node):
def__init__(self, include_file, block_name):
self.include_file=include_fileself.block_name=block_namedef_get_node(self, template, context, name):
''' taken originally from http://stackoverflow.com/questions/2687173/django-how-can-i-get-a-block-from-a-template '''fornodeintemplate:
ifisinstance(node, BlockNode) andnode.name==name:
returnnode.nodelist.render(context)
elifisinstance(node, ExtendsNode):
returnself._get_node(node.nodelist, context, name)
raiseException("Node '%s' could not be found in template."%name)
defrender(self, context):
t=get_template(self.include_file)
returnself._get_node(t, context, self.block_name)
The text was updated successfully, but these errors were encountered:
StackOverflow 2687173 has an interesting use case using a templatetag that we could easily support:
The text was updated successfully, but these errors were encountered: