Xzya / django-web-components

A simple way to create reusable template components in Django.
MIT License
159 stars 4 forks source link

Nesting components #11

Open pbi7521 opened 10 months ago

pbi7521 commented 10 months ago

This is really a wonderful package. I just love it. Makes my life so much easier.

I was wondering if you could agree with the following : it would be nice to have the ability to nest components and use their inner_block slots "normally". At the present moment, that generates a recursion error.

Here is an example

`component1 :

{% render_slot slots.inner_block %}

`

`component2 : {% component1 %}

Some dummy content I would like to show

{% render_slot slots.inner_block %} {% endcomponent1 %}`

Xzya commented 10 months ago

Hello,

A simple solution to this is to capture the slot into a variable before entering the component1 block, e.g.:

{% with inner_block=slots.inner_block %}
    {% component1 %}
        Some dummy content I would like to show

        {% render_slot inner_block %}
    {% endcomponent1 %}
{% endwith %}