Add named slots
alex-way opened this issue · comments
Alexander Way commented
It would be really cool if you could have both named and unnamed slots, rather than children - Similar to Astro and Svelte.
Alexander Way commented
I guess this is actually possible using fragments, although I would prefer it if the fragment was defined within the body of the component to assure that it was co-located.
Happy with fragments for now though.
Matthias Schoettle commented
Could you show an example how this can be achieved with fragments?
Alexander Way commented
@mschoettle
It's possible with code similar to the below:
<!-- components/button_with_label.html -->
<label>{{ label_text }}</label>
<button>{{ button_text }}</button>
<!--templates/index.html-->
{% fragment as button_text %}
Hello button
{% endfragment %}
{% fragment as label_text %}
Hello label
{% endfragment %}
{% #button_with_label button_text=button_text label_text=label_text %}{% /button_with_label %}