title: Flask / Jinja - render user input jinja template inside parent template with scope/context from parent
body: <p>The title is a mess, so let me be as clear as possible. How can I implement <code>do_magic</code>?</p>
  
  <p><strong>In this template.html</strong></p>
  
  <pre><code>{% set x = 1 %}
  {{ do_magic(subtemplate) }}, {{ x }}, {{ y }}
  </code></pre>
  
  <p><strong>Called from this method</strong></p>
  
  <pre><code>@app.route('/')
  def home():
    return render_template(
      'template.html',
      subtemplate='{{ x }}, {{ y }}',
      y=2,
      do_magic=do_magic
    )
  
  def do_magic(some_text):
      ... # what goes here?
  </code></pre>
  
  <p><strong>Which should output this</strong></p>
  
  <pre><code>1, 2, 1, 2
  </code></pre>
  
  <p><strong>And NOT this</strong></p>
  
  <pre><code>{{ x }}, {{ y }}, 1, 2
  </code></pre>