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

Post_Template::render_content │ protected │ WC 1.0

Renders the post-template block content using a table-based grid layout.

Method of the class: Post_Template{}

No Hooks.

Returns

string.

Usage

// protected - for code of main (parent) or child class
$result = $this->render_content( $block_content, $parsed_block, $rendering_context ): string;
$block_content(string) (required)
Block content.
$parsed_block(array) (required)
Parsed block.
$rendering_context(Rendering_Context) (required)
Rendering context.

Post_Template::render_content() code WC 11.1.2

protected function render_content( string $block_content, array $parsed_block, Rendering_Context $rendering_context ): string {
	if ( '' === trim( $block_content ) ) {
		return $block_content;
	}

	$dom          = new Dom_Document_Helper( $block_content );
	$list_element = $this->find_post_template_list( $dom );

	// If we can't find the post-template list, leave the original content untouched so we never
	// degrade output for markup shapes we don't recognize.
	if ( null === $list_element ) {
		return $block_content;
	}

	$items = $this->extract_list_items( $dom, $list_element );
	if ( empty( $items ) ) {
		return $block_content;
	}

	$columns = $this->get_column_count( $parsed_block, $dom, $list_element );

	// Single-column (list/flow/constrained) layouts already stack correctly in email; only the
	// multi-column grid/flex layouts need to be rebuilt as a table.
	if ( $columns < 2 ) {
		return $block_content;
	}

	// The layout width (minus the email's root padding) is what each cell's images are sized to,
	// so an image CDN / Outlook get a concrete pixel width rather than the intrinsic file width.
	$layout_width = (int) Styles_Helper::parse_value( $rendering_context->get_layout_width_without_padding() );

	return $this->build_grid_table( $items, $columns, $dom, $list_element, $layout_width );
}