carbon-fields
carbon-fields copied to clipboard
Make it possible to register custom script in new Block
This pull request makes it possible to set a custom script for the frontend and backend (editor) for the block.
Followed the same exact patterns used by the set_style methods.
How to use it:
wp_register_script('shiny_block', get_template_directory_uri().'/assets/js/block-test.js', [], false, true);
wp_register_script('shiny_block_editor', get_template_directory_uri().'/assets/js/block-test-editor.js', [], false, true);
Block::make( __( 'My Shiny Gutenberg Block 2' ) )
->set_script('shiny_block')
->set_editor_script('shiny_block_editor')
->set_render_callback( function ( $fields, $attributes, $inner_blocks ) {
?>
<div class="block">
....
</div><!-- /.block -->
<?php
} );
Don't know if it's a bug or simply by design. But in the editor interface it runs both scripts.
This attend partially to a feature requested in #664 .
Hello,
I would like to add also some javascript scripts if one custom block is used... It will be great also to add a parameter to choose a priority - it will allow to choose the order of the scripts. Add priority field to style too
Hi @labmorales ,
Thank you for your PR, we've implemented our solution for this issue in the new release.
@HTMLBurger-NG how was it implemented? Can't seem to find any reference to it.