I’m implementing a python flask webapp and I’m trying to write a macro to which I want to pass three blocks of html-code, but couldn’t get it run.
I found a simple example on making use of jinja with fastapi here: https://www.slingacademy.com/article/fastapi-how-to-use-macros-in-jinja-templates/?utm_content=cmp-true
I expected that it works, but I couldn’t get it run. I tried it and got the error message: “jinja2.exceptions.TemplateAssertionError: block ‘content’ defined twice”.
{% macro panel(title, class='panel') %}
<div class="{{ class }}">
<h2>{{ title }}</h2>
{% block content %}{% endblock %}
</div>
{% endmacro %}
{% call(panel, title='My Panel') %}
{% block content %}
<p>This is a panel content.</p>
{% endblock %}
{% endcall %}
Should this example work or is there a bug in the jinja2 template? Is there an alternative/better way to pass html-code blocks to a macro? I recognized the “caller” approach, but I think it only works with one code block, right?
Thank you!
Kind regards,
Jerome