[Django]-Jinja2 templating with components? blocks? templates?

6๐Ÿ‘

โœ…

I found the answer well hidden in the jinja2 docs

http://jinja.pocoo.org/docs/2.9/templates/#block-assignments

so you use a macro and a block assignment e.g. like this:

{% set section_content %}
<table><tr><td>etc</td> <td>etc</td> <td>etc</td></tr></table>
<table><tr><td>etc</td> <td>etc</td> <td>etc</td></tr></table>
<table><tr><td>etc</td> <td>etc</td> <td>etc</td></tr></table>
  {% endset %}
  {{  render_full_size_section(section_content)  }}


  {% set section_content %}
  aaaaaaaaaaa
    {% endset %}
    {{  render_full_size_section(section_content)  }}

wonder what they were doing pre 2.8โ€ฆ dark dark middle age

then in the macro:

{% macro render_full_size_section(content) %}
<div class="mycoolsection">
  {{ content | safe }}
</div>
{% endmacro %}
๐Ÿ‘คToskan

Leave a comment