Block theme. Block in now show in editor when script returns markup

[ad_1]

Hello.

I’m really sorry to bother you people with this easy problem, but

I’m tryind to start theme project with blocks.

I’m using wp-env as dev env.

Also use wordpress/scripts to build code. this works fine.

my block is shown in redactor if my Edit.js function returns underfined.

i can see title as defined in block.js

i can add block to redactor area. save and than see markup on fornt-end, that will be produced by render.php file.

but if i try to return some markup from Edit.js function, if block already added it appears to be broken and unsupportted and if it was not added to the redactor, then i just can’t see it in block menu.

block.json

{
“$schema”: “https://schemas.wp.org/trunk/block.json”,
“apiVersion”: 3,
“name”: “minsk-rn/header”,
“version”: “0.1.0”,
“category”: “widgets”,
“title”: “Header – RN”,
“style”: “file:./index.css”,
“editorScript”: “file:./index.js”,
“render”: “file:./render.php”
}

import ‘./index-style.css’;

import { registerBlockType } from ‘@wordpress/blocks’;
import { Edit } from “./edit”;
import metadata from ‘./block.json’;

registerBlockType( , {
edit: Edit
}metadata.name

and with this Edit.js function block won’t be in redactor

export function Edit(){
return (
<div>
<p>Test</p>
</div>
)
}

if i return export function Edit(){

return

}

block will be in redactor.

no errors in console. no error in dev script running. it emits builded code fine.

maybe some can suggest something to look for.

i tried to use xampp

went through some videos.

looked in docs.

but don’t understand this behavior) why my block disappear from redactor and block menu if Edit functio returns markup.

wordpress/scripts is running, code is being emmited to build folder.

blocks is located in theme folder/src

registered with

//ADD BLOCKS
add_action(“init”, function () {
register_block_type(__DIR__ . “/build/header”);
});

ty

[ad_2]
3 Comments
  1. thring to install npx u/wordpress/create-block@latest test –variant=dynamic

    ready block. but it’s not visible in block menu also.

  2. one important addition.

    if i return just string from edit function, e.p “text”

    block appear in editor

    registerBlockType( metadata.name, {
    edit: () => {
    return “text”
    }
    } );

    i can see in editor text “text”

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer