Control Template sections dynamically

Hi,
I’m using Materialize collapsible to customize the base template for my App (https://www.tutorialspoint.com/materialize/materialize_collapsible.htm), and I would like to add and delete sections dynamically from functions, for example for each new plot, I will define a new collapsible object in the template, fill it with a panel object and then display my template.
For this, I saved the new template in a separate html file called “template.html”, but when I tried to reuse It, It doesn’t work.
==> In my template.html I add this bloc:

ul class=“collapsible”
data-collapsible = “expandable”>
{% block sections %}
{% endblock %}
/ul>

==> In my code to add for example a plot:


It shows nothing in the server!
Any Help please :slight_smile:

You seem to be defining a block which isn’t present in the base template. The body section of the base template looks like this:

{% block body %}
<body>
    {% block inner_body %}
    {% block contents %}
        {% for doc in docs %}
        {{ embed(doc) if doc.elementid }}
        {% for root in doc.roots %}
            {{ embed(root) | indent(10) }}
        {% endfor %}
        {% endfor %}
    {% endblock %}
    {{ plot_script | indent(8) }}
    {% endblock %}
</body>
{% endblock %}

So you probably want to use {% block contents %} instead of {% block sections %}. You also have to actually add the Materialize CSS and JS though and you can define that in the postamble block:

{% block postamble %}
// Load Materialize CSS and JS here
{% endblock %}
1 Like