You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Expected $block variable in the function render_block
Actual Behavior
I tried to get post id in Gutenberg block Query loop. And found that usesContext are available only inside block.
Than I font that Carbon fields don't have $block variable inside render_callback method.
Before Changes
publicfunctionrender_block( $attributes, $content ) {
$fields = $attributes['data'];
$post_id = $this->get_post_id();
// Unset the "data" property because we// pass it as separate argument to the callback.
unset($attributes['data']);
ob_start();
call_user_func( $this->render_callback , $fields, $attributes, $content, $post_id );
returnob_get_clean();
}
After cahnges:
publicfunctionrender_block( $attributes, $content, \WP_Block$block = null ) { // added variable at the end $fields = $attributes['data'];
$post_id = $this->get_post_id();
// Unset the "data" property because we// pass it as separate argument to the callback.
unset($attributes['data']);
ob_start();
call_user_func( $this->render_callback , $fields, $attributes, $content, $post_id, $block ); // added variable at the end $toReturn = ob_get_contents();
ob_clean(); // changed way to get content from object otherwise $block is nullreturn$toReturn;
}
// are easy to reproduce
Steps to Reproduce the Problem
I tried to get post id in Gutenberg block Query loop. And found that usesContext are available only inside block.
Than I font that Carbon fields don't have $block variable inside render_callback method.
Comments
Please add any other comments here
The text was updated successfully, but these errors were encountered:
Version
Expected Behavior
Expected $block variable in the function render_block
Actual Behavior
I tried to get post id in Gutenberg block Query loop. And found that usesContext are available only inside block.
Than I font that Carbon fields don't have $block variable inside render_callback method.
Before Changes
After cahnges:
Steps to Reproduce the Problem
I tried to get post id in Gutenberg block Query loop. And found that usesContext are available only inside block.
Than I font that Carbon fields don't have $block variable inside render_callback method.
Comments
Please add any other comments here
The text was updated successfully, but these errors were encountered: