Closed vvaldesc closed 3 months ago
I'm seeing undefined as well. However, I was able to resolve this by restoring my version of the component in Storyblok's backend, and using the name I setup originally. This could have been an issue with the data not pulling in with the proper field name.
import { storyblokEditable } from '@storyblok/astro'
import StoryblokComponent from '@storyblok/astro/StoryblokComponent.astro'
const { blok } = Astro.props
// if (!blok.services) {
// throw new Error(
// "Cannot render StoryblokComponent. 'services' prop is undefined."
// );
// }
// Log the entire 'blok' to verify its structure
//console.log('Full blok:', JSON.stringify(blok, null, 2));
console.log('Services:', blok.services);
---
<main {...storyblokEditable(blok)}>
{
blok.services?.map((blok) => {
return <StoryblokComponent blok={blok} />
})
}
</main>```
@vvaldesc I just checked with multiple nested components, and it's working as expected. However, I noticed an issue in your Main.astro
component. I believe you're implementing it incorrectly, which is causing the problem. Your Main.astro
file should be quite similar to your Page.astro
file.
As per the screenshot you shared, you have named the field block
in your Storyblok schema, so it will be blok.block
. Since it's an array, you need to map it and then pass each block to the StoryblokComponent
like this: <StoryblokComponent blok={blok} />
.
Main.astro
---
import { storyblokEditable } from "@storyblok/astro";
import StoryblokComponent from "@storyblok/astro/StoryblokComponent.astro";
const { blok } = Astro.props;
---
<div {...storyblokEditable(blok)} class="container">
{
blok.block?.map((blok) => {
return <StoryblokComponent blok={blok} />;
})
}
</div>
<style>
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
width: 90%;
margin: 0 auto;
}
</style>
Hi @vvaldesc, We are closing this PR as we have not heard back from you. In the future, you can reopen it if you still think this is an issue.
Thanks for your attention, I will try this soon.
I can't use one component within another and I can't find any information in the documentation.
The input parameter of the Main block is supposed to be another blok, I understand that in code this will be a storyblok component, when I nest main with another component it fails and I'm not able to fix it, my only alternative is not to use nested elements right now.
Expected Behavior
No error, StoryblokComponent working properly
Current Behavior
Cannot render StoryblokComponent. 'blok' prop is undefined.
components/StoryblokComponent.astro:16:9
Steps to Reproduce
CMS web:
Main is the nestable element.
Main props:
Index.astro:
Main.astro:
astro config:
Package.json:
Thank you for your attention