Automattic\WooCommerce\EmailEditor\Engine\Renderer\ContentRenderer
Content_Renderer::render_block
Renders block Translates block's HTML to HTML suitable for email clients. The method is intended as a callback for render_block
Method of the class: Content_Renderer{}
Hooks from the method
Returns
String.
Usage
$Content_Renderer = new Content_Renderer(); $Content_Renderer->render_block( $block_content, $parsed_block ): string;
- $block_content(string) (required)
- Block content.
- $parsed_block(array) (required)
- Parsed block.
Content_Renderer::render_block() Content Renderer::render block code WC 10.7.0
public function render_block( string $block_content, array $parsed_block ): string {
/**
* Filter the email-specific context data passed to block renderers.
*
* This allows email sending systems to provide context data such as user ID,
* email address, order information, etc., that can be used by blocks during rendering.
*
* Blocks that need cart product information can derive it from the user_id or recipient_email
* using CartCheckoutUtils::get_cart_product_ids_for_user().
*
* @since 1.9.0
*
* @param array $email_context {
* Email-specific context data.
*
* @type int $user_id The ID of the user receiving the email.
* @type string $recipient_email The recipient's email address.
* @type int $order_id The order ID (for order-related emails).
* @type string $email_type The type of email being rendered.
* }
*/
$email_context = apply_filters( 'woocommerce_email_editor_rendering_email_context', array() );
$context = new Rendering_Context( $this->theme_controller->get_theme(), $email_context );
$block_type = $this->block_type_registry->get_registered( $parsed_block['blockName'] );
$result = null;
try {
if ( $block_type && isset( $block_type->render_email_callback ) && is_callable( $block_type->render_email_callback ) ) {
$result = call_user_func( $block_type->render_email_callback, $block_content, $parsed_block, $context );
}
} catch ( \Exception $error ) {
$this->logger->error(
'Error thrown while rendering block.',
array(
'exception' => $error,
'block_name' => $parsed_block['blockName'],
'parsed_block' => $parsed_block,
'message' => $error->getMessage(),
)
);
// Returning the original content.
return $block_content;
}
if ( null === $result ) {
$result = $this->fallback_renderer->render( $block_content, $parsed_block, $context );
}
return $this->add_root_horizontal_padding( $result, $parsed_block['email_attrs'] ?? array() );
}