@register.tag<EOL>def angularjs(parser, token):
bits = token.contents.split()<EOL>if len(bits) < <NUM_LIT:2>:<EOL><INDENT>bits.append('<STR_LIT:1>')<EOL><DEDENT>values = [parser.compile_filter(bit) for bit in bits[<NUM_LIT:1>:]]<EOL>django_nodelist = parser.parse(('<STR_LIT>',))<EOL>angular_nodelist = NodeList()<EOL>for node in django_nodelist:<EOL><INDENT>if isinstance(node, VariableNode):<EOL><INDENT>tokens = node.filter_expression.token.split('<STR_LIT:.>')<EOL>token = tokens[<NUM_LIT:0>]<EOL>for part in tokens[<NUM_LIT:1>:]:<EOL><INDENT>if part.isdigit():<EOL><INDENT>token += '<STR_LIT>' % part<EOL><DEDENT>else:<EOL><INDENT>token += '<STR_LIT>' % part<EOL><DEDENT><DEDENT>node = TextNode('<STR_LIT>' % token)<EOL><DEDENT>angular_nodelist.append(node)<EOL><DEDENT>parser.delete_first_token()<EOL>return AngularJsNode(django_nodelist, angular_nodelist, values[<NUM_LIT:0>])<EOL>
Conditionally switch between AngularJS and Django variable expansion for ``{{`` and ``}}``
keeping Django's expansion for ``{%`` and ``%}``

Usage::

    {% angularjs 1 %} or simply {% angularjs %}
        {% process variables through the AngularJS template engine %}
    {% endangularjs %}

    {% angularjs 0 %}
        {% process variables through the Django template engine %}
    {% endangularjs %}

    Instead of 0 and 1, it is possible to use a context variable.