Automattic\WooCommerce\EmailEditor\Integrations\Core\Renderer\Blocks

Abstract_Block_Renderer::add_spacerprotectedWC 1.0

Add a spacer around the block for vertical spacing (margin-top).

Horizontal root padding is applied uniformly by Content_Renderer::render_block() so that all blocks — including those using render_email_callback without Abstract_Block_Renderer — receive consistent padding.

Method of the class: Abstract_Block_Renderer{}

No Hooks.

Returns

String.

Usage

// protected - for code of main (parent) or child class
$result = $this->add_spacer( $content, $email_attrs ): string;
$content(string) (required)
The block content.
$email_attrs(array) (required)
The email attributes.

Abstract_Block_Renderer::add_spacer() code WC 10.8.1

protected function add_spacer( $content, $email_attrs ): string {
	// Filter out empty margin-top values to prevent malformed CSS output.
	$margin_top_attrs = array_intersect_key( $email_attrs, array_flip( array( 'margin-top' ) ) );
	if ( isset( $margin_top_attrs['margin-top'] ) && '' === trim( $margin_top_attrs['margin-top'] ) ) {
		$margin_top_attrs = array();
	}

	$gap_style = WP_Style_Engine::compile_css( $margin_top_attrs, '' ) ?? '';

	$table_attrs = array(
		'align' => 'left',
		'width' => '100%',
		'style' => $gap_style,
	);

	$div_content = sprintf(
		'<div class="email-block-layout" style="%1$s">%2$s</div>',
		esc_attr( $gap_style ),
		$content
	);

	return Table_Wrapper_Helper::render_outlook_table_wrapper( $div_content, $table_attrs );
}