title: Passing HTML to a Jinja macro
body: <p>My page has many Bootstrap modals which always have the same markup, except for the identifiers and the actual content of course.</p>
  
  <p>To minimize the enormous and repetetive amount of code for these modals I want to build a Jinja macro that spits out the entire HTML markup for a modal with one simple call, e.g.:</p>
  
  <pre><code>{# macros/modal_template.jinja2 #}
  
  {% macro print_modal(id, title, body_content) %}
    &lt;div class="modal fade" id="{{ id }}" tabindex="-1"&gt;
      &lt;div class="modal-dialog"&gt;
         &lt;div class="modal-content"&gt;
          &lt;div class="modal-header"&gt;
            &lt;button type="button" class="close" data-dismiss="modal"&gt;&lt;span&gt;&amp;times;&lt;/span&gt;&lt;/button&gt;
            &lt;h4 class="modal-title"&gt;{{ title }}&lt;/h4&gt;
          &lt;/div&gt;
          &lt;div class="modal-body"&gt;
            {{ body_content }}
          &lt;/div&gt;
          &lt;div class="modal-footer"&gt;
            &lt;button type="button" class="btn btn-default" data-dismiss="modal"&gt;Close&lt;/button&gt;
            &lt;button type="button" class="btn btn-primary"&gt;Save changes&lt;/button&gt;
          &lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  {% endmacro %}
  
  
  {# my_page.jinja2 #}
  
  {% from "macros/modal_template.jinja2" import print_modal %}
  &lt;html&gt;
  &lt;body&gt;
    {{ print_modal("description-modal", "Description", "Lorem Ipsum") }}
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>So far it's pretty much a no-brainer, but image <code>body_content</code> isn't a plain string, but a complex HTML form or a really long text with text-styling HTML. I'm struggling to find a good solution to this problem.</p>
  
  <p>The only working solution I came up with so far is to pass the content as a string and printing it with <code>{{ body_content|safe }}</code>, but putting complex markup into a string is ugly and uncomfortable.</p>
  
  <p>Do you guys have any good ideas?</p>