4 ms·
For templating, that is why I prefer Jinja2 with macros instead of Django templates. {% macro IssueCard(issue, type) -%} ... lot of HTML {% endmacro -
by mariocesar 2y ago
For templating, that is why I prefer Jinja2 with macros instead of Django templates.
{% macro IssueCard(issue, type) -%}
... lot of HTML
{% endmacro -%}
{% for issue in myissues %}
{% macro IssueCard(issue, 'myissue') %}
{% endfor %}
The alternative is creating template tags, which can be a lot of work, and it gets you out of the templates.
I have a folder called macros/ where I put all the macros I need, and then I use the import call from Jinja2.
I agree with you; having long and deeply nested HTML templates creates too much noise when developing. Jinja2 Macros help with that.