django-components icon indicating copy to clipboard operation
django-components copied to clipboard

Make `{% component %}` play well with `{% block %}`

Open EmilStenstrom opened this issue 3 years ago • 2 comments

It seems to me that {% block %} tags should be executed first, and only after blocks are filled should components parse and fill their slots. This would enable use-cases as:

{% block content %}
    {% component_block 'calendar' date="2021-01-01" %}
        {% slot 'header' %}Calendar for January{% endslot %}
    {% endcomponent %}
{% endblock %}

As well as:

{% component_block 'calendar' date="2021-01-01" %}
    {% slot 'header' %}{% block content %}{% endblock %}{% endslot %}
{% endcomponent %}

Currently only the first example works, and not the second one, because slots gets executed before blocks.

I'm not sure if there's an easy way to solve this, but I think we should examine if there is. If it's not possible to solve, let's at least document the shortcoming to solve people some trouble.

EmilStenstrom avatar Feb 05 '22 12:02 EmilStenstrom

Django principle when dealing with NESTED blocks is the same as THE LIBRARY, if you tried to use nested BLOCKS it won't work, I don't see it as an issue, once I'm using the BLOCK on the inheriting child, it means I'm redefining its structure including everything declared inside of it from the parent.

housUnus avatar Feb 13 '23 20:02 housUnus

{% block test_parent %}
    parent from base
    {% block test_child %}
        child_from_bbase
    {% endblock test_child %}
{% endblock test_parent %}


{% extends "base.html" %}
{% block test_parent %}
    parent_from_skelton 
    {% block test_child %}
        child_from_skelton
    {% endblock test_child %}
{% endblock test_parent %}

This would print : parent_from_skelton child_from_skelton just as SLOTS work

housUnus avatar Feb 13 '23 20:02 housUnus