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

Post_Template::build_grid_table │ private │ WC 1.0

Build the grid as one <table> per row wrapped in a container table.

Follows the tiled-gallery pattern (Gallery::build_gallery_table()): items are chunked into rows of $columns and each row is its own fixed-layout table, so every cell keeps a consistent width regardless of how many items the final (possibly partial) row holds.

Method of the class: Post_Template{}

No Hooks.

Returns

string. Grid table HTML.

Usage

// private - for code of main (parent) class only
$result = $this->build_grid_table( $items, $columns, $dom, $list_element, $layout_width ): string;
$items(array<int, string>) (required)
Inner HTML of each list item.
$columns(int) (required)
Number of columns.
$dom(Dom_Document_Helper) (required)
Parsed block content.
$list_element(DOMElement) (required)
The post-template list element (for wrapper classes).
$layout_width(int) (required)
Available layout width in px.

Post_Template::build_grid_table() code WC 11.1.2

private function build_grid_table( array $items, int $columns, Dom_Document_Helper $dom, \DOMElement $list_element, int $layout_width ): string {
	$cell_width = $this->get_cell_width( $layout_width, $columns );

	$rows       = array();
	$item_count = count( $items );
	for ( $i = 0; $i < $item_count; $i += $columns ) {
		$rows[] = $this->build_grid_row( array_slice( $items, $i, $columns ), $columns, $cell_width );
	}
	$grid_content = implode( '', $rows );

	$original_class = $dom->get_attribute_value( $list_element, 'class' );

	$table_attrs = array(
		'class' => trim( 'email-block-post-template ' . Html_Processing_Helper::clean_css_classes( $original_class ) ),
		'style' => 'width: 100%; border-collapse: collapse;',
		'width' => '100%',
	);

	return Table_Wrapper_Helper::render_table_wrapper( $grid_content, $table_attrs );
}