-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
svelte:content #7634
Comments
Do you think named slots already achieve this? |
@babichjacob Slots can't be passed to sibling components. This is a slimmed down version of what I have in my layout file:
Banner is where the banner contents are displayed/styled, but Page is the one that sets the banner contents. Banner contents varies per page. Currently there is no native way to set content for one component via another. I either have to bubble an event up to the parent and back down, or set content on a store, but storing HTML in a svelte store feels wrong. |
I would also say that named slots are a good approach. It depends a bit on how your layout component is used. Here is one example that might work for youLayout.svelte:<main>
<Header />
<Banner>
<slot slot="page-header-title" name="page-header-title" />
<slot slot="page-header-action" />
</Banner>
<slot />
</main> Banner.svelte: <div>
<h1>
<slot name="page-header-title" />
</h1>
<div class="actions">
<slot name="page-header-action" />
</div>
</div> and lastly Page.svelte: <Layout>
<svelte:fragment slot="page-header-title">
Test
</svelte:fragment>
<svelte:fragment slot="page-header-action">
<a href="..."></a>
</svelte:fragment>
Remaining page content here...
</Layout> This setup of course assumes that you can decide where, how and when your layout component is instantiated. |
Describe the problem
Each page has a different page header. Need a way to pass data from the main page view to a child of the layout view. Currently complicated using stores. Would clean things up using a method like Ruby on Rails content_for by allowing svelte:fragment to accept a name, and be able to call it later with svelte:content
Describe the proposed solution
In the page view:
In the page banner component:
Alternatives considered
Open to suggestions
Importance
would make my life easier
The text was updated successfully, but these errors were encountered: