Template tag to denote a template section to render a second time via a middleware.
Usage:
{% load phased_tags %}
{% phased with [var1] [var2] .. %}
.. some content to be rendered a second time ..
{% endphased %}
You can pass it a list of context variable names to automatically save those variables for the second pass rendering of the template, e.g.:
{% load phased_tags %}
{% phased with comment_count object %}
There are {{ comment_count }} comments for "{{ object }}".
{% endphased %}
Alternatively you can also set the PHASED_KEEP_CONTEXT setting to True to automatically keep the whole context for each phased block.
Note: Lazy objects such as messages and csrf tokens aren’t kept.
Taken from django.templatetags.cache and changed ending tag.
This will cache the contents of a template fragment for a given amount of time and do a second pass render on the contents.
Usage:
{% load phased_tags %}
{% phasedcache [expire_time] [fragment_name] %}
.. some expensive processing ..
{% phased %}
.. some request specific stuff ..
{% endphased %}
{% endphasedcache %}
This tag also supports varying by a list of arguments:
{% load phased_tags %}
{% phasedcache [expire_time] [fragment_name] [var1] [var2] .. %}
.. some expensive processing ..
{% phased %}
.. some request specific stuff ..
{% endphased %}
{% endphasedcache %}
Each unique set of arguments will result in a unique cache entry. The tag will take care that the phased tags are properly rendered.
It requires usage of RequestContext and django.core.context_processors.request to be in the TEMPLATE_CONTEXT_PROCESSORS setting.
Parse to the end of a phased block. This is different than Parser.parse() in that it does not generate Node objects; it simply yields tokens.