title: In Jinja2, how can I use macros in combination with block tags?
body: <p>I'm a front end developer, and I've been trying to get a hang on using Jinja2 effectively. I want to tweak a current site so it has multiple base templates using inheritance, it fully uses block tags to substitute content and override it, and uses macros to support passing of arguments.</p>
  
  <p>My base template contains this code (edited for simplicity):</p>
  
  <pre><code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
  "http://www.w3.org/TR/html4/strict.dtd"&gt;
  {% from "foo.html" import macro1, macro2, macro3 %}
  {% macro base_template(title=none, arg2=none, urls={}, arg3=false) %}
  &lt;html&gt;
    &lt;title&gt;{{ title }} | Site.com&lt;/title&gt;
    ....
    {{ caller() }}
    ....
  &lt;/html&gt;
  {% endmacro %}
  
  {% block content %}{% endblock %}
  </code></pre>
  
  <p>And my pages that extend it look like this:</p>
  
  <pre><code>{% extends "base.html" %}
  {% block content %}
  {% call base_template(title="home", arg2="active", arg3="true") %}
  (html code here)
  {% endcall %}
  {% endblock %}
  </code></pre>
  
  <p>So basically all the pages extend base, they call a macro and pass arguments to that macro. I don't quite understand it all, but the main point is that this allows default values and a degree of flexibility that doesn't require redefining an entire block: it gives some degree of flexibility and power. Again this is heavily simplified.</p>
  
  <p>The only problem is, this negates my ability to use blocks. Macros are for flexibility, but with blocks, I have the ability to override something entirely, or use it's parents contents and add to it, which I can't do with Macros (at least I don't think). The problem is, I can't wrap things in blocks, else they won't see the values in the macro. For instance, doing this:</p>
  
  <pre><code>{% block title %}&lt;title&gt;{{ title }} | Site.com&lt;/title&gt;{% endblock %}
  </code></pre>
  
  <p>Will fail because it will say title is undefined. </p>
  
  <p>Ultimately I am looking for a way to utilize both the power and organiztional aspects of blocks, but still be able to utilize the logic &amp; terseness of macros. If anyone could give me any help as to how I might go about this problem, I would really appreciate it.</p>