Comments on: Why and How to Create a Gutenberg Block – A Tutorial for Beginners https://torquemag.io/2019/05/create-gutenberg-block/ All the Word that's fit to Press Thu, 03 Mar 2022 12:22:54 +0000 hourly 1 https://wordpress.org/?v=6.6.1 By: Nick Schäferhoff https://torquemag.io/2019/05/create-gutenberg-block/#comment-892233 Thu, 03 Mar 2022 12:22:54 +0000 https://torquemag.io/?p=86787#comment-892233 In reply to Paul Roos.

Thank you and gerne!

]]>
By: Paul Roos https://torquemag.io/2019/05/create-gutenberg-block/#comment-892160 Thu, 03 Mar 2022 06:53:42 +0000 https://torquemag.io/?p=86787#comment-892160 Very well written. Viele dank!

]]>
By: Reid Walley https://torquemag.io/2019/05/create-gutenberg-block/#comment-518311 Sat, 18 Jul 2020 21:31:17 +0000 https://torquemag.io/?p=86787#comment-518311 Thanks for confirming to use Mac Terminal in Step #2. Mac Console is a log viewer, generally used for troubleshooting when there is a problem with the computer.

]]>
By: Nick Schäferhoff https://torquemag.io/2019/05/create-gutenberg-block/#comment-517750 Fri, 17 Jul 2020 09:19:57 +0000 https://torquemag.io/?p=86787#comment-517750 In reply to Reid Walley.

Is there a difference? I don’t have a Mac… But it should be the terminal.

]]>
By: Reid Walley https://torquemag.io/2019/05/create-gutenberg-block/#comment-517682 Fri, 17 Jul 2020 04:52:34 +0000 https://torquemag.io/?p=86787#comment-517682 On Step #2, do you mean Mac Console or Mac Terminal?

]]>
By: Nick Schäferhoff https://torquemag.io/2019/05/create-gutenberg-block/#comment-499683 Mon, 01 Jun 2020 14:37:10 +0000 https://torquemag.io/?p=86787#comment-499683 In reply to Justice Beya.

Hey Justice,

below is what I have in my block.js file. Let me know if I can help in some other way.

/**
* BLOCK: cta-block
*
* 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

/**
* Register: aa Gutenberg Block.
*
* Registers a new block provided a unique name and an object defining its
* behavior. Once registered, the block is made editor as an option to any
* editor interface where blocks are implemented.
*
* @link https://wordpress.org/gutenberg/handbook/block-api/
* @param {string} name Block name.
* @param {Object} settings Block settings.
* @return {?WPBlock} The block, if it has been successfully
* registered; otherwise `undefined`.
*/

( function( blocks, editor, element ) {
var el = element.createElement;
var RichText = editor.RichText;

blocks.registerBlockType( 'cgb/block-cta-block', {
title: 'CTA Block',
icon: 'testimonial',
category: 'common',

attributes: {
content: {
type: 'array',
source: 'children',
selector: 'p',
},
},

edit: function( props ) {
var content = props.attributes.content;
function onChangeContent( newContent ) {
props.setAttributes( { content: newContent } );
}

return el(
RichText,
{
tagName: 'p',
className: props.className,
onChange: onChangeContent,
value: content,
}
);
},

save: function( props ) {
return el( RichText.Content, {
tagName: 'p', value: props.attributes.content,
} );
},
} );
}(
window.wp.blocks,
window.wp.editor,
window.wp.element
) );

]]>
By: Nick Schäferhoff https://torquemag.io/2019/05/create-gutenberg-block/#comment-499679 Mon, 01 Jun 2020 14:31:16 +0000 https://torquemag.io/?p=86787#comment-499679 In reply to Elliot.

Happy to help!

]]>
By: Elliot https://torquemag.io/2019/05/create-gutenberg-block/#comment-499252 Sun, 31 May 2020 14:40:39 +0000 https://torquemag.io/?p=86787#comment-499252 Very useful tutorial! Thank you 🙂

]]>
By: Justice Beya https://torquemag.io/2019/05/create-gutenberg-block/#comment-497987 Thu, 28 May 2020 09:07:33 +0000 https://torquemag.io/?p=86787#comment-497987 Hey Nick
May you share the code you use in block.js; I followed this tutorial and I got stuck on step 5.
I’m confused on the code to use in registerBlockType(), edit:() and save:().
Please !

]]>
By: Nick Schäferhoff https://torquemag.io/2019/05/create-gutenberg-block/#comment-448447 Fri, 17 Jan 2020 11:03:31 +0000 https://torquemag.io/?p=86787#comment-448447 In reply to Chris.

Hey Chris, I would guess that there is a way to set up a custom block with functions.php and have all the files in your theme folder. However, I haven’t looked into that. Plus, with a custom plugin, it’s easier to re-use your blocks on other websites or switch them off when you don’t need them anymore.

]]>