Allow to define multiple slots with the same name to render a single fill in multiple places #419
Closed
JuroOravec
started this conversation in
Ideas
Replies: 2 comments 1 reply
-
I'm a little hazy on the details here, but I think this has to do with nested components needing to have unique slot names amongst themselves? {% component "card" %}
{% fill "header" %} <!-- Error? -->
{% component "profile" %}
{% fill "header" %} <!-- Error? -->
Title
{% endfill %}
{% endcomponent %}
{% endfill %}
{% endcomponent %} I'm a little worried that components with dynamic slots (slots that might not exist depending on some if statements) like the conditional one you describe above will be hard to understand and reason about. Could your example be rewritten as: {% slot "myslot" %}
{% if myvar %}
...
{% else %}
...
{% endif %}
{% endslot %} |
Beta Was this translation helpful? Give feedback.
1 reply
-
Implemented in #453 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
As part of #416, I came across this snippet:
https://github.com/EmilStenstrom/django-components/blob/master/src/django_components/component.py#L332
Basically it prevents multiple slots with the same name to be defined in a template, e.g.:
At my work, we've hit this error when we wanted to render a single slot fill in different places based on some conditions, e.g.:
Intuition tells me that this should not be an error. Basically, if I define a slot in multiple places, the fill should simply populate all the slots, so the first example would render:
Was there a specific reason why a slot multiple times leads to errors?
I haven't looked into it, but my guess is that it throws an error because it's simply not implemented. Because when I consider the example above, then the way slots are managed behind the scenes probably needs to be refactored if the slots are to allow supporting re-use.
Simply consider this example, where we use a single slot twice, but in each case it has a different default content:
Beta Was this translation helpful? Give feedback.
All reactions