Block enqueued files not work with reusable block
-
I have created a new block and enqueued a css file for it like this
$id = get_the_ID(); if(has_block('lazyblock/uni-ybox',$id)){ wp_register_style('uniyboxstyle', get_template_directory_uri() . '/css/yBox.min.css', array('unibsstyle'), null, 'all'); wp_enqueue_style('uniyboxstyle'); // Enqueue it! }
unibsstyle is a dependency style. Now it works fine and load css file only when that particular block is being used on any page or post.
But problem happen when we put that block inside a reusable block. The has_block condition stop working. and I have to change the condition to something like this
if(has_block('lazyblock/uni-ybox',$id) || has_block('block {"ref":341}', $id ) ){
Where 341 is the id of the reusable block created. But this is not an ideal way to do this.Either blocks enqueued files should be supported directly by the reusable blocks or there should be some standard has_reusable_block function condition to allow enqueue files when block used in any reusable block created.
- The topic ‘Block enqueued files not work with reusable block’ is closed to new replies.