#NEWLINE# @ register . tag ( name = 'captureas' ) #NEWLINE# def do_captureas( parser , token ) : #NEWLINE# #INDENT# '\n    Assign to a context variable from within a template\n        {% captureas my_context_var %}<!-- anything -->{% endcaptureas %}\n        <h1>Nice job capturing {{ my_context_var }}</h1>\n    ' #NEWLINE# try : #NEWLINE# #INDENT# ( tag_name , args ) = token . contents . split ( None , 1 ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# raise template . TemplateSyntaxError ( "'captureas' node requires a variable name." ) #NEWLINE# #UNINDENT# nodelist = parser . parse ( ( 'endcaptureas' , ) ) #NEWLINE# parser . delete_first_token ( ) #NEWLINE# return CaptureasNode ( nodelist , args )