I could not get to work. When published the content the attribute innerContent didn't save. Here is what I tried.
block.js
// Import CSS.
import './style.scss';
import './editor.scss';
const { __ } = wp.i18n;
const { registerBlockType } = wp.blocks;
const { RichText } = wp.editor;
registerBlockType( 'hall/block-server-side-render', {
title: __( 'Server Side Rendering' ),
icon: 'shield',
category: 'common',
keywords: [
__( 'Server Side Rendering' )
],
attributes: {
innerContent: {
type: 'array',
source: 'children',
selector: 'p'
}
},
edit: function( props ) {
function onChangeContent( content ) {
props.setAttributes( { innerContent: content } );
}
return (
<div className={ props.className }>
<div class="gray-bg">
<RichText tagName="p" role="textbox" aria-multiline="true" value={props.attributes.innerContent} onChange={onChangeContent} />
</div>
</div>
);
},
save: function( props ) {
return null;
},
} );
init.php
register_block_type( 'hall/block-server-side-render', array(
'render_callback' => 'hall_render_inner_content',
'attributes' => array(
'innerContent' => array(
'type' => 'array'
)
)
));
function hall_render_inner_content( $attributes ) {
$innerContent = $attributes['innerContent'];
return '<div class="inner-content">' . $innerContent . '</div>';
}
onChangeContent()
):props.attributes(
- and that should beprops.setAttributes(
..