Control Template sections dynamically

I’m using Materialize collapsible to customize the base template for my App (, 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 %}

==> 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 %}
    {% 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 %}
{% 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