@register.tag(name='<STR_LIT>')<EOL>def do_capture(parser, token):
bits = token.split_contents()<EOL>t_as = '<STR_LIT>'<EOL>t_silent = '<STR_LIT>'<EOL>var = '<STR_LIT>'<EOL>silent = False<EOL>num_bits = len(bits)<EOL>if len(bits) > <NUM_LIT:4>:<EOL><INDENT>raise TemplateSyntaxError("<STR_LIT>")<EOL><DEDENT>elif num_bits == <NUM_LIT:4>:<EOL><INDENT>t_name, t_as, var, t_silent = bits<EOL>silent = True<EOL><DEDENT>elif num_bits == <NUM_LIT:3>:<EOL><INDENT>t_name, t_as, var = bits<EOL><DEDENT>elif num_bits == <NUM_LIT:2>:<EOL><INDENT>t_name, t_silent = bits<EOL>silent = True<EOL><DEDENT>else:<EOL><INDENT>var = '<STR_LIT>'<EOL>silent = False<EOL><DEDENT>if t_silent != '<STR_LIT>' or t_as != '<STR_LIT>':<EOL><INDENT>raise TemplateSyntaxError("<STR_LIT>")<EOL><DEDENT>nodelist = parser.parse(('<STR_LIT>',))<EOL>parser.delete_first_token()<EOL>return CaptureNode(nodelist, var, silent)<EOL>
Capture the contents of a tag output.
Usage:

.. code-block:: html+django

    {% capture %}..{% endcapture %}                    # output in {{ capture }}
    {% capture silent %}..{% endcapture %}             # output in {{ capture }} only
    {% capture as varname %}..{% endcapture %}         # output in {{ varname }}
    {% capture as varname silent %}..{% endcapture %}  # output in {{ varname }} only

For example:

.. code-block:: html+django

    {# Allow templates to override the page title/description #}
    <meta name="description" content="{% capture as meta_description %}{% block meta-description %}{% endblock %}{% endcapture %}" />
    <title>{% capture as meta_title %}{% block meta-title %}Untitled{% endblock %}{% endcapture %}</title>

    {# copy the values to the Social Media meta tags #}
    <meta property="og:description" content="{% block og-description %}{{ meta_description }}{% endblock %}" />
    <meta name="twitter:title" content="{% block twitter-title %}{{ meta_title }}{% endblock %}" />