#Is there a way to pass data to a "global" slot?

5 messages · Page 1 of 1 (latest)

foggy dagger
#

I'm currenly creating a Astro + Storyblok website and ran into a little issue. I need to set metadata from a (grand)child component.

Since Storyblok supplies their own StoryblokComponent i cant make use of transferring slots to pass data around to multiple levels.

What i've tried so far: (simplified version)

// src/layouts/Layout.astro
<html>
  <head>
    <Head />
    <slot name="head" />
  </head>
  <body>
    <slot />
  </body>
</html>

// src/pages/[...slug].astro
<Layout>
  <StoryblokComponent blok={story.content} story={story} />
</Layout>

// src/components/storyblok/SomeNestedStoryBlokComponent.astro
<SomeNestedStoryBlokComponent>
  <h1>Page title</h1>

  <Fragment slot="head">
    <title>Page title - My Website</title>
  </Fragment>
</SomeNestedStoryBlokComponent>

Is there a possibility to use something like we have in next/nuxt? Or as the title describes use something like a global slot? <slot name="head" is-global />

// src/components/storyblok/SomeNestedStoryBlokComponent.astro
---
import { useHead } from 'some-package';

useHead({
  title: 'Page title - My Website'
});
---
<SomeNestedStoryBlokComponent>
  <h1>Page title</h1>
</SomeNestedStoryBlokComponent>
dense pelican
#

We don't have this feature currently, but there's a proposal for something similar

#

Now what you could do is have a wrapper component for the storyblok component which will be used to pass around slots

#

Let me know how that goes!