Support Forum
As requested several times in this forum, it would be really nice to see an instant preview of the block render code even if there was no user input. However, only displaying "Click the Edit icon in the block toolbar to enter content." is not very convenient since you can't see on which block you are on, at least without the list view enabled. As an maybe easier to implement alternative: What do you think about options to render the Blocks Title and Description, or make the "Click the Edit icon in the block toolbar to enter content." message editable?
Hello Aaron
Thanks for your suggestion.
Currently, MB Blocks does not support rendering a block without any user input, it is not meaningful. Instead of trying to create a block like that, I think you can create your own shortcode and add the shortcode to a Shortcode block. It would have the same purpose since you do not want to allow the customer to add something.
Hey Peter,
you got me wrong. The block has indeed user input, but the user needs to input something. To see what it is about, it would be nice to giving users a clue what the block inside the editor is about without having to take a look in sidebars (the mb blocks sidebar is almost useless since the only thing it shows are the mb blocks title and the advanced tab). An use case for this could be a page template. The MB Blocks initial state renders only, "Click the Edit icon in the block toolbar to enter content." Besides that I disagree: Rendering a block without user input is indeed meaningful, since in the current state 'std' values are confusing because they don't trigger a render inside the editor, like a real input would do.
You can take this as a feature request.
A minimal approach would be turning this initial state from https://imgur.com/pJo5UU2 into something like this https://imgur.com/BW0Ettw, but an initial preview is much appreciated to provide a nicer user experience.
Thanks for your feedback.
I will inform the development team to consider supporting this case in future updates.
I agree, both points. Furthermore, that block/edit message over a no-preview block looks really really rough, can this please be considered as that really spoils user experience in Gutenberg.
Have a workaround for this, but it's not ideal as to implement you'll need edit the plugin.
I install the plugin into the theme so it's not an issue, but if it's via the WP Plugins system the edits will get overridden.
File: mb-blocks/src/Block.php
Find $attributes = wp_unslash( $attributes );
on line 81 and add the following after that.
`
if ( empty($attributes['data']) && ! empty($this->meta_box['defaults']) ) {
$attributes['data'] = $this->meta_box['defaults'];
}
`
Then on the block config array, you can add a defaults
array key containing any default values you want the block to render with. In doing this you bypass the UX issue described.
Found a bug as a result of the above where the default data wont save. Another hacky workaround is to edit the compiled JS file in mb-blocks/assets/blocks.js adding the below just after line 160
$(el.current).find('input').trigger('change');
(I realise it's not a good idea to edit plugins)