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

Post_Template::build_grid_row │ private │ WC 1.0

Build a single grid row as its own fixed-layout table.

Every cell is a fixed 100 / $columns percent wide and a partial final row is padded with empty cells, so items stay aligned to their column and keep a uniform width across rows (unlike the gallery, which stretches a partial row to fill the width). This matches how a CSS grid keeps column tracks consistent — important when the items are logos that shouldn't change size row to row.

Method of the class: Post_Template{}

No Hooks.

Returns

string. Row table HTML.

Usage

// private - for code of main (parent) class only
$result = $this->build_grid_row( $row_items, $columns, $cell_width ): string;
$row_items(array<int, string>) (required)
Inner HTML of the items in this row.
$columns(int) (required)
Total number of columns.
$cell_width(int) (required)
Cell content width in px.

Post_Template::build_grid_row() code WC 11.1.2

private function build_grid_row( array $row_items, int $columns, int $cell_width ): string {
	$cell_width_percent = 100 / $columns;
	$cells              = '';

	for ( $col = 0; $col < $columns; $col++ ) {
		$cell_content = isset( $row_items[ $col ] ) ? $this->prepare_item_content( $row_items[ $col ], $cell_width ) : '';
		$cell_attrs   = array(
			'style'  => sprintf(
				'width: %s; padding: %dpx; vertical-align: top; text-align: center;',
				Html_Processing_Helper::sanitize_css_value( sprintf( '%.4f%%', $cell_width_percent ) ),
				self::CELL_PADDING
			),
			'valign' => 'top',
		);
		$cells       .= Table_Wrapper_Helper::render_table_cell( $cell_content, $cell_attrs );
	}

	return sprintf(
		'<table role="presentation" style="width: %s; border-collapse: collapse; table-layout: fixed;"><tr>%s</tr></table>',
		Html_Processing_Helper::sanitize_css_value( '100%' ),
		$cells
	);
}