admin管理员组文章数量:1278690
I have a block that copies the functionality of the "Columns" block. My problem is that I don't want to use the default save
function, but use a callback function instead.
As I'm using InnerBlocks
my edit
looks something like this
edit: ( props, setAttributes, className ) => {
.
.
.
<InnerBlocks
template={ getColumnsTemplate( props.attributes.columns ) }
templateLock="all"
allowedBlocks={ ALLOWED_BLOCKS } />
By default, the save function outputs the content using this as return: <InnerBlocks.Content />
How should the render_callback
function in php look like in order to display the InnerBlocks
content?
Also if save
returns null
then the content I put inside block doesn't get saved.
I have a block that copies the functionality of the "Columns" block. My problem is that I don't want to use the default save
function, but use a callback function instead.
As I'm using InnerBlocks
my edit
looks something like this
edit: ( props, setAttributes, className ) => {
.
.
.
<InnerBlocks
template={ getColumnsTemplate( props.attributes.columns ) }
templateLock="all"
allowedBlocks={ ALLOWED_BLOCKS } />
By default, the save function outputs the content using this as return: <InnerBlocks.Content />
How should the render_callback
function in php look like in order to display the InnerBlocks
content?
Also if save
returns null
then the content I put inside block doesn't get saved.
- I'm not sure that server rendered blocks support nesting – Tom J Nowell ♦ Commented Oct 4, 2021 at 9:51
1 Answer
Reset to default 5save (JS)
By default, the save function outputs the content using this as return:
<InnerBlocks.Content />
This part is ok, you should still return <InnerBlocks.Content />
in your save function:
save: props => <InnerBlocks.Content />
Source
If you are using InnerBlocks in a dynamic block you will need to save the InnerBlocks in the save callback function using
<InnerBlocks.Content/>
https://developer.wordpress/block-editor/tutorials/block-tutorial/creating-dynamic-blocks/
render_callback (PHP)
function render($attributes, $content)
{
return $content;
}
Source
Whatever you return in save function is in $content variable of PHP render function`
https://github/WordPress/gutenberg/issues/6751#issuecomment-451550734
本文标签: block editorHow to display InnerBlocks in render callback
版权声明:本文标题:block editor - How to display InnerBlocks in render callback 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741288327a2370402.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论