title: How to pass custom template tags to Jinja2 Template class?
body: <p>For example, I attached Jinja2 to my pythonic project with the next code (<a href="http://jinja.pocoo.org/docs/intro/#basic-api-usage" rel="nofollow">Jinja2 docs</a>):</p>
  
  <pre><code>from jinja2 import Template
  template = Template(text_of_the_template)
  template.render(**kwargs)
  </code></pre>
  
  <p>The example of using a custom template tag (from <a href="https://groups.google.com/forum/#!topic/pocoo-libs/YscFKoSlLpE" rel="nofollow">here</a>):</p>
  
  <pre><code> from jinja2 import contextfunction
  
   @contextfunction
   def widget(context, template_name, **extra_context):
       t = jinja_env.get_template('widgets/' + template_name)
       ctx = dict(context.items())
       ctx.update(extra_context)
       return t.render(ctx)
  
   jinja_env.globals['widget'] = widget
  
  # And then in the template:
  
  {{ widget('last_tweets.html') }}
  </code></pre>
  
  <p>How to bind Jinja2 environment and the code above (the Template class)?</p>