-
Notifications
You must be signed in to change notification settings - Fork 0
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
In layout, multiple slots with name attributes cannot be supported[✨] #103
Comments
How would this feature look like? i cant see how named slots are useful in layouts? how pages would specify the named slot? |
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 |
I think |
@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:
|
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). |
this is essential. still waiting. |
How do other meta-fws solve this problem? Can you point to examples? |
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. |
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) |
@mhevery If we use the Might found a bug. |
Right, this is because the The PS: Sorry, I don't have a good answer for you. |
@mhevery |
@mhevery |
Great! Can this issue be closed? |
@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. |
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. |
@mhevery Yes, I would love to do that. And get some pointers on where to go. After reading |
|
How is this going forward? |
Just chiming in to +1. The benefit of |
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 |
@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? |
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'
};
}; |
Actually just looking up the tree might be problematic. How about |
We moved this issue to |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
The text was updated successfully, but these errors were encountered: