I got a result after 4 hours of stupid try & error
I’m unable to read values from source meta in the frontend.
I assigned the variable from meta to a regular string attribute and it works. Easy Peasy.
/**
* BLOCK: bold-blocks
*
* Registering a basic block with Gutenberg.
* Simple block, renders and saves the same content without any interactivity.
*/
// Import CSS.
import './style.scss';
import './editor.scss';
const {__} = wp.i18n; // Import __() from wp.i18n
const {registerBlockType} = wp.blocks; // Import registerBlockType() from wp.blocks
const {ServerSideRender} = wp.components;
const {AlignmentToolbar, BlockControls, InspectorControls,} = wp.editor;
const {
PanelBody,
PanelRow,
Fragment
} = wp.element;
registerBlockType('cgb/block-bold-blocks', {
// Block name. Block names must be string that contains a namespace prefix. Example: my-plugin/my-custom-block.
title: __('bold-blocks - Example Meta Content'), // Block title.
icon: 'shield', // Block icon from Dashicons → https://developer.wordpress.org/resource/dashicons/.
category: 'common', // Block category — Group blocks together based on common traits E.g. common, formatting, layout widgets, embed.
keywords: [
__('bold-blocks — CGB Block'),
__('CGB Example'),
__('create-guten-block'),
],
attributes: {
metaToDisplay: {
type: 'string',
source: 'meta',
meta: 'werk',
},
className: {
type: 'string',
default: 'fuck'
},
werkId: {
type: 'string',
value: 'foo',
default: 'shit'
}
},
edit(props) {
// const {attributes: {metaToDisplay, className}, setAttributes, isSelected} = props;
let metaToDisplay = props.attributes.metaToDisplay;
let className = props.className;
props.setAttributes( { werkId: metaToDisplay } );
props.werkId = props.metaToDisplay;
return (
<ServerSideRender
block="cgb/block-bold-blocks"
attributes={{
metaToDisplay: metaToDisplay,
className: className,
werkId: metaToDisplay
}}
/>
)
;
},
save: function (props) {
// const {attributes: {metaToDisplay, className}, setAttributes} = props;
// Rendering in PHP
return null;
},
});
I’m sure, that I’m doing some kind of cargo cult here. Can somebody provide me a more elegant solution for my problem?