#NEWLINE# def connect( self , name , fn ) : #NEWLINE# #INDENT# '\n        Connect a function ``fn`` to the template hook ``name``.\n\n        An example hook could look like this::\n\n            function my_hook(sender, **kwargs):\n                # Get the request from context\n                request = kwargs[\'context\'][\'request\']\n                kwargs[\'content\'].append("Hello, {0}!".format(request.user))\n\n            registry.connect(\'hookname\', name)\n\n        If the given hook name does not exist at runtime, it is created\n        dynamically.\n        ' #NEWLINE# with _registry_lock : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# signal = self . _registry [ name ] #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# signal = self . register ( name ) #NEWLINE# #UNINDENT# #UNINDENT# signal . connect ( fn )