python - Django template tag modifies the context of only one block -
i made template tag objective of simplifying inclusion of angular.
the tag responsible setting variables in context following:
@register.simple_tag(takes_context=true) def ng_controller(context, controller_name, file_name): context['angular_import'] = true context['angular_controller_file'] = file_name return 'ng-controller="{}"'.format(controller_name)
the root template has block in place of javascript imports
{% block container_content %}{% endblock %} {% block angular_inclusion %}{% endblock %}
the template inherits root template this
{% extends 'root.html' %} {% block container_content %} <div class="row"> <div class="col-sm-12"> <div class="well" {% ng_controller 'createedictcontroller' 'js/controllers/create-edict-controller.js' %}> {{ angular_controller_file }} </div> </div> </div> {% endblock %} {% block angular_inclusion %} {{ angular_controller_file }} {% endblock %}
i can access {{ angular_controller_file }}
in first block, not in second block. how can ensure context manipulation affects second block also?
variable scope in context
any variable set in context available in same block of template in assigned. behavior intentional; provides scope variables don’t conflict context in other blocks.
so tag call in first block container_content
:
<div class="well" {% ng_controller 'createedictcontroller' 'js/controllers/create-edict-controller.js' %}>
is ignored , missing in second block, angular_inclusion
Comments
Post a Comment