Nested blocks of the same block type? #4238
benjamin-p-newton
started this conversation in
General
Replies: 2 comments 2 replies
-
I am struggling with the same issue, have you found the solution yet? |
Beta Was this translation helpful? Give feedback.
1 reply
-
Hey there, i have got the same issue. const getSectionBlock = (maxDepth: number = 3): Block => {
return {
slug: 'section-block',
labels: {
plural: {
de: 'Inhalte',
},
singular: {
de: 'Inhalt',
},
},
fields: {
...(maxDepth > 0
? [
{
name: 'nestedBlocks',
type: 'blocks',
blocks: [
getSectionBlock(maxDepth - 1),
],
},
]
: []),
},
}
}
export const SectionBlock = getSectionBlock() Create a function that returns the needed fields and then iterate over a number, in that case maxDepth to prevent maximum call stack exceeded error, which for each iteration returns a spreaded array of a block that calls itself and lowers the maxdepth variable. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
As per the title, is it possible to have a block type reference itself?
Using the a modified version of the 'Content' block from on of the payload cms templates, I've demonstrated what I'm trying to achieve below:
Beta Was this translation helpful? Give feedback.
All reactions