I assigned the variable from meta to a regular string attribute and it works. Easy Peasy.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | /** * 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; }, }); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.