Treat layout pages like components when using named slots
See original GitHub issueLet’s say I have a _layout.svelte
like the following:
<slot name="layout-pre"></slot>
<div id="intermediate">Some other intermediate stuff.</div>
<slot></slot>
And now I have a child view (let’s call it homepage.svelte
which inherits that layout, which puts some stuff into the named slot, and the rest into the default slot:
<h1 slot="layout-pre">This should come before #intermediate.</h1>
<!-- When rendered, the div from above should get inserted here from the layout:
<div id="intermediate">Some other intermediate stuff.</div>
-->
<main>Since this doesn't use a named slot, it'll just get inserted into the unnamed slot above.</main>
Right now this is not allowed, and the following error is thrown: Element with a slot='...' attribute must be a descendant of a component or custom element
. Are there technical or usage reasons why we wouldn’t want to treat a layout like any other component with respect to slots?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:198
- Comments:44 (14 by maintainers)
Top Results From Across the Web
Using templates and slots - Web Components | MDN
Slots are identified by their name attribute, and allow you to define placeholders in your template that can be filled with any markup...
Read more >Slots - Vue.js
When a component accepts both a default slot and named slots, all top-level non- <template> nodes are implicitly treated as content for the...
Read more >A comprehensive guide to Svelte components with slots
Take a deep dive into Svelte components with slots by learning how they work and how to use them to supercharge your Svelte...
Read more >Shadow DOM slots, composition
Let's see how slots work on a simple example. ... In the shadow DOM, <slot name="X"> defines an “insertion point”, a place where...
Read more >Vue layout with named slots - Stack Overflow
The default slot works, but "header" slot doesn't display itself (unless using MyLayout as standard component). vue.js · slot · Share.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Any updates on this? This is still quite the annoyance.
I agree, without this feature any dynamic sidebar becoming a disaster.