Automattic\WooCommerce\EmailEditor\Engine\Renderer\ContentRenderer
Content_Renderer::add_root_horizontal_padding
Wrap block output with horizontal padding (root + container).
Root padding is distributed by the Spacing_Preprocessor from the outer email container to individual blocks. Container padding comes from template groups wrapping post-content. Both are combined into a single CSS padding wrapper. This method applies padding uniformly to all blocks regardless of whether they use Abstract_Block_Renderer or a custom render_email_callback.
Method of the class: Content_Renderer{}
No Hooks.
Returns
String. The content wrapped with horizontal padding, or unchanged if no padding.
Usage
// private - for code of main (parent) class only $result = $this->add_root_horizontal_padding( $content, $email_attrs ): string;
- $content(string) (required)
- The rendered block content.
- $email_attrs(array) (required)
- The email attributes from the parsed block.
Content_Renderer::add_root_horizontal_padding() Content Renderer::add root horizontal padding code WC 10.7.0
private function add_root_horizontal_padding( string $content, array $email_attrs ): string {
$padding_left = $this->sum_padding_values(
$email_attrs['root-padding-left'] ?? null,
$email_attrs['container-padding-left'] ?? null
);
$padding_right = $this->sum_padding_values(
$email_attrs['root-padding-right'] ?? null,
$email_attrs['container-padding-right'] ?? null
);
$css_attrs = array();
if ( $padding_left > 0 ) {
$css_attrs['padding-left'] = $padding_left . 'px';
}
if ( $padding_right > 0 ) {
$css_attrs['padding-right'] = $padding_right . 'px';
}
if ( empty( $css_attrs ) ) {
return $content;
}
$padding_style = WP_Style_Engine::compile_css( $css_attrs, '' );
if ( empty( $padding_style ) ) {
return $content;
}
$table_attrs = array(
'align' => 'left',
'width' => '100%',
);
$cell_attrs = array(
'style' => $padding_style,
);
$div_content = sprintf(
'<div class="email-root-padding" style="%1$s">%2$s</div>',
esc_attr( $padding_style ),
$content
);
return Table_Wrapper_Helper::render_outlook_table_wrapper( $div_content, $table_attrs, $cell_attrs );
}