title: How do I build reusable widgets in jinja2?
body: <p>I want to define a widget something vaguely like this:</p>
  
  <pre><code>{% block css %}
  .mywidget {
       css: goes_here;
  {% endblock %}
  
  {% block widget %}
  &lt;div class="mywidget"&gt;
     &lt;!-- structure goes here --&gt;
  &lt;/div&gt;
  {% endblock %}
  
  {% block script %}
  $( ".mywidget" ).addFunctionality(stuff)
  {% endblock %}
  </code></pre>
  
  <p>In other words, a deceleration of what CSS the widget needs, what its contents are (preferably parametrized in some way), and what scripts it requires at the end of the file. Then, I would like to be able to extend a layout template, add widgets to the body (possibly multiple widgets of the same type with different parameters of some kind), and have the CSS and javascript properly added to the top and bottom of the layout template, once per widget type.</p>
  
  <p>This seems like a pretty clean and straightforward design, and coming from a native UI design perspective, I am confused as to why I cannot find any examples of how to do something like this.</p>