This looks like a good way how to create a reference from parent to child if I have a Accordion or a Slider blocks with child bloks as individuals accordion items or slides.
@RyanWelcherCodes Жыл бұрын
That’s a great use-case for context. Thanks for sharing!
@jeffersoncarvalho2566 Жыл бұрын
Hello. Is there a way to hook into js script for core blocks or add my custom styles and script, like passing a viewScript in block.json on custom blocks? I want to add javascript to core/quote block but i want the view.js (or my custom js) only be enqueued if the block is on the page. I achieved this by creating a core/quote block in my theme with the viewScript, but not registering the block, since the block is already registered. I had to register manually the block styles and script. For the styles, using "wp_enqueue_block_style" solves. But for the viewScript, i had to use "render_block" filter, check if the blockName is "core/quote" and then, enqueue the script.
@RyanWelcherCodes11 ай бұрын
That's exactly how I'd do it as well. There is currently no hook available to do this. You can also use the dedicated hook for that block to remove the need to check the block - developer.wordpress.org/reference/hooks/render_block_this-name/