I have a template tag that includes a template:
def WidgeLoaderNode(IncludeNode):
def __init__(tpl, scopes=None):
self.scopes = scopes
self.tpl = tpl
super(WidgeLoaderNode, self).__init__('""')
def render(self, context):
self.template_name = self.tpl.resolve(context)
scopes = self.scopes.resolve(context) if options else DEFAULT_SCOPES
context.push()
context['form'] = ScopeForm(scopes)
fragment = super(WidgeLoaderNode, self).render(context)
context.pop()
return fragment
@register.tag
def widget_form(parser, token):
bits = token.split_contents()
tpl = parser.compile_filter(bits[1])
scopes = parser.compile_filter(bits[2]) if len(bits) > 2 else None
return WidgeLoaderNode(tpl, scopes)
The template has to be specified from the template. In those templates, I need to include a couple of tag libraries:
{% load widgets_tags helpers %}
. Is it possible to reduce boilerplate template code in them by loading those libraries from my node code?
Maybe you could use something like this: http://djangosnippets.org/snippets/342/ – i.e. django.template.add_to_builtins