Log1x / poet

Configuration-based post type, taxonomy, block category, and block registration for Sage 10.
https://github.com/Log1x/poet
MIT License
205 stars 16 forks source link

Blocks not showing up in WP editor #22

Closed StudioRATATA closed 3 years ago

StudioRATATA commented 3 years ago

Hi Brandon,

I'm unable to get the blocks to work in the editor. What I noticed is that the CPT books from the /config/poet.php does show up. These are the steps I took. Not that I did them both on my existing sage 10 project and a clean install of a sage 10 project. Both with the same result.

With this I don's see the block in the editor. I also changed the namespace and block name to check with more unique names.

Is there something I'm not doing right?

Log1x commented 3 years ago

did you register the block in javascript?

e.g.

import { __ } from '@wordpress/i18n'
import { registerBlockType } from '@wordpress/blocks'
import { InnerBlocks } from '@wordpress/block-editor'

/** components */
import edit from './edit.js'

registerBlockType(`block/accordion`, {
  title: __(`Accordion`, `sage`),
  category: `formatting`,
  icon: `format-image`,
  attributes: {
    accordions: {
      type: 'array',
      default: [{ label: 'New accordion' }],
    },
  },
  edit,
  save: () => <InnerBlocks.Content />,
})
aitormendez commented 3 years ago

I have "Unable to locate publishable resources" too.

Log1x commented 3 years ago

Do wp acorn vendor:publish without specifying the provider and choose from the list (working on a fix in Acorn)

StudioRATATA commented 3 years ago

did you register the block in javascript?

Ah no, I did not. I naively assumed the plugin handled the block registration, much like the acf approach in Log1x/acf-composer since I read nothing about it in the readme. I've worked with wp-blocks boilerplates before. They watch and build the .js files and the build files are being served.

If I place your snippit simply in a /App/blocks/accordion/block.js file (along with a editor.js file) and enqeue them I get an Es6 import error. So I guess I miss extra steps and knowledge :)

How would I handle this?


The wp acorn vendor:publish did the trick, thanks. I've had this with several composer plugins. I can now use this elsewhere as well. Thanks Brandon.

StudioRATATA commented 3 years ago

Literately seconds later I figured I could place this in the assets folder... Like /resources/assets/scripts/blocks/accordion/block.js And import them in the editor.js. No luck yet, but now, it builds : )

-- edit -- Even though I typed editor here, I actually placed it in the app.js. Now it all shows up in the wp - editor . Party-party!

May I suggest to make a note of this in the readme? The part of needing to add the registerBlockType() to the assets folder and a reference to the documentation. Or better yet, a code example from, like you just shared. -- end edit --

haynzz commented 3 years ago

I have to be honest, if it wasn't for this issue thread I would not have been able to get it running. But, now it worked for me. I assume it's because I'm new to everything. I have no experience in WP Theme development and I have started with sage10. So, I have also never created my own Gutenberg block before. The major issues that needed trial and error and closer reading for me were:

  1. I have to register via the new block via editor.js - got to know the registerBlockType this way
  2. the namespaces have to match everywhere (sage/<myblock> by default) so that the resources/views/blocks/<myblock>.balde.php file is loaded – learned that it works as I expect it when I do not provide a save property during block registration
    • Disclaimer not tried to get InnerBlocks working yet

One question that is still open for me: Can I set the block-category for a block in the poet.php or does it need to be via registerBlockType in the JS files?

-- EDIT -- I forgot to thank you @Log1x for this package. It was still fun to figure the things out from above. -- EDIT --

-- EDIT 2-- I think I have finally understood why the confusion. This package is to get a server side configured more easily mostly for existing blocks – amongst all the other things like taxonomy etc. It does not to be in the scope of the package to create custom blocks. I think the confusion started since I landed on this repo from a link in another discussion that was about custom block creation. Now, I understand how to use this package. -- EDIT 2--