Add support for layouts with multiple (named) slots
See original GitHub issueHi, i would like to use layouts with multiple slots but did not find a way to reference any named slots from within a page.
Example (layout/default.vue):
<template>
<header>
<h1>Website</h1>
<slot name="header" />
</header>
...
<main>
<slot />
</main>
</template>
Vue pages can only contain a single <template>
tag, maybe a custom component that works like like <Head>
could be the solution.
Example (pages/index.vue):
<template>
<SlotContent name="header">
<h2>Important headline</h2>
</SlotContent>
<p>Other content</p>
</template>
Issue Analytics
- State:
- Created a year ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
No results found
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
No results found
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
I implemented a proof-of-concept, which enables
.vue
pages to pass slots to the parent layout using the standard syntax:The only downside is that it requires an additional SFC parse of
.vue
pages on each pass so it’s a bit slower (although it’s only a few ms). I’d like to benchmark it in a slower computer before deciding to go ahead with this change.Please give it a try, and let me know how it goes 😃
Closing for now as I haven’t found any implementation without serious downsides, see #114 for further details.
If you need to provide HTML to layouts, you can use the following pattern:
Layout
src/layouts/default.vue
Page
Opt-out of the default layout using
layout="false"
, and add an existing layout to the template, passing named slots as usual.Have in mind that iles automatically exposes existing layouts using the
<${Name}Layout>
convention, no need to import them.It’s not as terse as the proof-of-concept, but it’s not too bad either.