Replies: 25 comments
-
How would this feature look like? i cant see how named slots are useful in layouts? how pages would specify the named slot? |
Beta Was this translation helpful? Give feedback.
-
I found myself wanting this for a layout that consisted of a sidebar and content area. On child routes I wanted to add sub-navigation specific to the child route to the sidebar while rendering the main child content into the content area. Without something like named slots in layout, would the recommended pattern be to keep the logic in the parent layout to conditionally render the appropriate sub-navigation based on the active child route? I'm just learning Qwik so I won't speculate on a possible API (or if it's even a good idea to introduce named layout slots). Possibly related: QwikDev/qwik#2429 |
Beta Was this translation helpful? Give feedback.
-
I think |
Beta Was this translation helpful? Give feedback.
-
@adamdbradley, @manucorporat I like @genki's suggestion. If we want to make it clear that the content is to be projected to a named slot, some token could be introduced in the name, like we do when we want to use a specific layout (by following the Maybe for the slots we could use something in that direction, for example using squared brackets:
|
Beta Was this translation helpful? Give feedback.
-
Hi, same thing : it would be great ! I tried to make a side navbar for custom routes on the left for an educational platform, where the menu would vary depending on the part of the tree of the course (section/chapters/pages), and thought named Slots would be ideal in layout, where we could populate the link in the layout through the Slot identifier. The useContent() needs a lot of workarounds to come to that result (didn't succeed yet). |
Beta Was this translation helpful? Give feedback.
-
this is essential. still waiting. |
Beta Was this translation helpful? Give feedback.
-
How do other meta-fws solve this problem? Can you point to examples? |
Beta Was this translation helpful? Give feedback.
-
I wanted to have something like this: // layout.tsx
export default component$(() => {
return (
<>
<div class='py-5'>
<Slot name='header' />
<section>
<Slot />
</section>
</div>
</>
);
}); // index.tsx
export default component$(() => {
return (
<>
<div q:slot='header'>header items</div>
<div>
article content
</div>
</>
);
}); named slots are not working in layout. |
Beta Was this translation helpful? Give feedback.
-
So the issue is show here: https://stackblitz.com/edit/qwik-starter-1pnxsm?file=src%2Froutes%2Findex.tsx import { Slot, component$ } from '@builder.io/qwik';
export default component$(() => {
return (
<Layout>
<Index />
</Layout>
);
});
export const Layout = component$(() => {
return (
<>
<div class="py-5">
<Slot name="header" />
<section style={{ border: '1px solid red' }}>
<Slot />
</section>
</div>
</>
);
});
// index.tsx
export const Index = component$(() => {
return (
<>
<div q:slot="header">header items</div>
<div>article content</div>
</>
);
}); The basic problem is that the <Layout>
<Index/>
</Layout> So the <Layout>
<div q:slot="header">header items</div>
<Index/>
</Layout> And that is not how routes are composed. I think this would be an issue for other meta-frameworks as well. How do they solve this problem? (I can't think of a way they would solve this) |
Beta Was this translation helpful? Give feedback.
-
@mhevery If we use the Might found a bug. |
Beta Was this translation helpful? Give feedback.
-
Right, this is because the The PS: Sorry, I don't have a good answer for you. |
Beta Was this translation helpful? Give feedback.
-
@mhevery |
Beta Was this translation helpful? Give feedback.
-
@mhevery |
Beta Was this translation helpful? Give feedback.
-
Great! Can this issue be closed? |
Beta Was this translation helpful? Give feedback.
-
@mhevery I don't believe it can be closed. What is described here is a workaround. Although it does work, it doesn't look very good and requires some scaffolding per layout and page. Also a first-time user of Qwik. Loving it so far. I would suggest something that is similar that works out of the box: // layout.tsx
export default component$(() => {
return (
<div class="wrapper">
<Header />
<Menu />
<Slot name="submenu" />
<Slot />
<Slot name="sidebar" />
<Footer />
</div>
)
}) // index.tsx
// Applied to the default Slot
export default component$(() => (<p>page content</p>))
// Applied to the named slots, if available
export const layoutSlots = {
sidebar: () => (<p>sidebar content</p>)),
submenu: () => (<p>submenu content</p>)),
} Should a layout's named slot not be defined in the page, it'll just remain empty. If a page defines a named Slot which is not available in the layout, it'll be ignored. In short: "If both are available, assign it to the slot. If either is unavailable, ignore it" This way we can keep it clean and consistent. |
Beta Was this translation helpful? Give feedback.
-
OK, I like your proposal and agree that this would be a good feature. (Sorry it took me so long to understand what you are asking.) Any chance you would be up for creating a PR for this? I would be happy to guide you through it. |
Beta Was this translation helpful? Give feedback.
-
@mhevery Yes, I would love to do that. And get some pointers on where to go. After reading |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
How is this going forward? |
Beta Was this translation helpful? Give feedback.
-
Just chiming in to +1. The benefit of |
Beta Was this translation helpful? Give feedback.
-
Hi, I started to work on this, but I don't seem to have the time anymore. I got to the point where caching the |
Beta Was this translation helpful? Give feedback.
-
@mhevery wouldn't it be possible to support this by skipping fragments when resolving slots? Then the Maybe you can address this in the v2 branch? |
Beta Was this translation helpful? Give feedback.
-
Would be great to have the ability of dynamic layouts, like in DocumentHead: export const layoutSlots = ({ resolveValue }) => {
const receipt = resolveValue(useRecipesDetails);
return {
headerContent : receipt
? <HeaderContent receipt={receipt}></HeaderContent>
: null
};
};
export const head: DocumentHead = ({ resolveValue }) => {
const receipt = resolveValue(useRecipesDetails);
return {
title : receipt ? receipt.title : 'Tastoria Receipt'
};
}; |
Beta Was this translation helpful? Give feedback.
-
Actually just looking up the tree might be problematic. How about |
Beta Was this translation helpful? Give feedback.
-
We moved this issue to |
Beta Was this translation helpful? Give feedback.
-
Is your feature request related to a problem?
In layout, multiple slots with name attributes cannot be supported.
Describe the solution you'd like
Can multiple slots be supported in the layout?
Describe alternatives you've considered
no idear
Additional context
No response
Beta Was this translation helpful? Give feedback.
All reactions