Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wp.blocks is undefined? #261

Open
ikiweb-it opened this issue Oct 14, 2024 · 2 comments
Open

wp.blocks is undefined? #261

ikiweb-it opened this issue Oct 14, 2024 · 2 comments

Comments

@ikiweb-it
Copy link

I'm trying to implement a custom block for the Isolated Block Editor outside of WordPress (I want to use Gutenberg for a web app that is NOT based on WP).

The editor works fine, but I'm unable to create custom blocks. I followed the usual procedure, but the block doesn't work, and I get this console error: window.wp.blocks.registerBlockType is undefined.

It seems "wp.blocks" is not exported, so I'm unsure how to extend it.

Can anyone help?

@johngodley
Copy link
Member

wp is only exported if you are using WP. You will need to bundle your block so it uses the library files directly.

@ikiweb-it
Copy link
Author

Thanks for the suggestions.

I followed the advice to bundle the Gutenberg libraries directly using @wordpress/blocks and @wordpress/block-editor since I’m not using WordPress.

However, my custom block still doesn't work (custom block doesn't appear in the editor).

Here’s the code I’m working with:

`import { registerBlockType } from '@wordpress/blocks';
import { RichText } from '@wordpress/block-editor';

// Registra un blocco semplice
registerBlockType('myplugin/ikiweb-blocks', {
title: 'IKIweb Blocks',
icon: 'smiley',
category: 'widgets',
edit: (props) => {
const { attributes: { content }, setAttributes } = props;
return (
<RichText
tagName="p"
value={content}
onChange={(newContent) => setAttributes({ content: newContent })}
placeholder="Inserisci testo..."
/>
);
},
save: (props) => {
const { attributes: { content } } = props;
return <RichText.Content tagName="p" value={content} />;
},
});`

I am using Isolated Block Editor and I have manually imported the necessary Gutenberg libraries as suggested.

Could someone help me understand where I am going wrong?

To complete: I repeat that the isolated editor works correctly, I am having serious problems exclusively in extending it with custom blocks. There are many tutorials on the Internet for those who use WP but for those who use the isolated editor there is no documentation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants