Skip to content

Commit

Permalink
feat: add support for slots
Browse files Browse the repository at this point in the history
  • Loading branch information
djam90 committed May 10, 2023
1 parent 7295a1b commit 4da0655
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,38 @@ Use `useStoryblok` in your pages to fetch Storyblok stories and listen to real-t
</template>
```

#### Using slots

You can use slots to insert slot content into the dynamic component:

```html
<script setup>
import { useStoryblok } from "@storyblok/vue";
const story = await useStoryblok("path-to-story", { version: "draft" });
</script>

<template>
<StoryblokComponent v-if="story" :blok="story.content">
<MyCustomComponent />
</StoryblokComponent>
</template>
```

And then in the dynamic component that `StoryblokComponent` uses, you can render the slot content as you would with regular Vue slots:

```html
<template>
<div>
<!-- Some content -->

<!-- The slot content MyCustomComponent will be rendered here -->
<slot></slot>

<!-- Some more content -->
</div>
</template>
```

#### Rendering Rich Text

You can easily render rich text by using the `renderRichText` function that comes with `@storyblok/vue` and a Vue computed property:
Expand Down
2 changes: 1 addition & 1 deletion lib/StoryblokComponent.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<component :is="blok.component" v-bind="{ ...$props, ...$attrs }"></component>
<component :is="blok.component" v-bind="{ ...$props, ...$attrs }" v-slots="{ ...$slots }"></component>
</template>

<script setup lang="ts">
Expand Down

0 comments on commit 4da0655

Please sign in to comment.