I have used the scaffolding to create a block that is react on the front end. The code is below.
As you can see I have added two fields to the block but I do not know how to get the values entered in those block inspector fields in my react code to use in the block. Does anyone know how to get those values?
Block.json
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2,
"name": "create-block/react-dynamic",
"version": "0.1.0",
"title": "Portfolio Block (react)",
"category": "embed",
"icon": "smiley",
"description": "Example block scaffolded with Create Block tool.",
"supports": {
"html": false
},
"attributes": {
"list_id": {
"type": "string"
},
"doubleoptin": {
"type": "boolean"
}
},
"textdomain": "example-dynamic",
"editorScript": "file:./editor.js",
"editorStyle": "file:./index.css",
"style": "file:./style-index.css",
"render": "file:./render.php"
}
render.php:
<p <?php echo get_block_wrapper_attributes(); ?>>
<div id="portfolio-block-react" style="overflow: hidden; max-width: 100%!important">
</div>
</p>
index.js:
/**
* Registers a new block provided a unique name and an object defining its behavior.
*
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/
*/
import { registerBlockType } from '@wordpress/blocks';
import ReactDOM from 'react-dom';
/**
* Lets webpack process CSS, SASS or SCSS files referenced in JavaScript files.
* All files containing `style` keyword are bundled together. The code used
* gets applied both to the front of your site and to the editor.
*
* @see https://www.npmjs.com/package/@wordpress/scripts#using-css
*/
import './style.scss';
/**
* Internal dependencies
*/
import Edit from './edit';
import metadata from './block.json';
import App from './App.js';
ReactDOM.render(<App />, document.getElementById('portfolio-block-react'));
/**
* Every block starts by registering a new block type definition.
*
* @see https://developer.wordpress.org/block-editor/reference-guides/block-api/block-registration/
*/
registerBlockType( metadata.name, {
/**
* @see ./edit.js
*/
edit: Edit,
} );
npm run installin the root, thennpm installandnpm run buildin the wordpress-block-react folder