-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
How to server render block with nested blocks? #6751
Comments
Is there a possibility of introducing multiple
This would be more useful. Currently it's only possible to achieve this using a workaround of creating a second block. This is almost acceptable. If I could save |
Is there a Timetable for this? We currently have a custom block with |
I’m going to dig into this today. As it turns out I need this for a client project myself, so I’ll report back what I find. |
I gave up on this and just accept that For my purposes, if the server-side render of an [
'my_container_title' => 'blah',
'my_inspector_field' => 'bleh',
'innerblocks' => [
[
'namespace' => 'core',
'name' => 'paragraph',
'attributes' => [ ... ],
'render_callback' => null,
'rendered' => '<p>...</p>'
],
[
'namespace' => 'superduper',
'name' => 'amazingblock',
'attributes' => [ ... ],
'render_callback' => 'superduper_function' // callable of any sort
'rendered' => '<div>...</div>'
],
...
]
] That's "all" that's needed. (Edited to add that knowing if there is a server-side render function registered would allow me to call that instead of relying on the pre-rendered content; in that way, if I have multiple custom blocks which do server-side renders I could provide them with context information in PHP, since that's nearly impossible to achieve in JS, apparently.) |
Hey sorry all for the delay but it is possible to have an InnerBlocks and render your block on the server. I have a sample plugin but have been offline today. I’ll push it up as soon as I can. |
@chrisvanpatten Hi! Got any update on this? |
Now it looks it works. Here are my examples: Here is how my JS save function of the block looks like. Whatever you return in save function is in $content variable of PHP render function. function save() {
return <InnerBlocks.Content />;
} and here is my render PHP function: function render($attributes, $content) {
return '<div>doing some server magic :) ' . uniqid() . '<br />' . $content . '</div>';
} So I would consider it as solved! |
It doesn't work if the innerblocks is a dynamic block as well... But if it's not dynamic it works... That definitely sounds like a bug |
Hi. This appears to be unrelated to the current issue. Feel free to open a new one, and if so please provide some context, such as intended use cases. Thanks. |
Did you find a solution for this? |
stil today I need a solution for the same problem |
Yes the issue was within my hooks, I really don't remember what was my issue and how I solved it but there is no issue there with gutenberg, I think maybe I just forgot to return the result in the dynamic block or I had a bad condition returning nothing |
guy's Any Solution? Has anyone been able to use the Parent Block $attributes to Child Block in the server? |
Hi,
I have a block that uses
InnerBlocks
that I want to have server-rendered:I'm trying to do a server-rendering:
I would imagine similar behaviour like with shortcodes where I get nested blocks in $content attribute. Is it something that is in the roadmap or something I can achieve now but don't know how?
Thank you.
Dan
The text was updated successfully, but these errors were encountered: