` whose grid is * laid out with CSS grid/flex. Email clients (Outlook especially) don't support those, so the grid * collapses to a single stacked column. This renderer re-flows the already-rendered `
  • ` items * into an email-safe, table-based column layout — mirroring how the Gallery renderer arranges * images (see {@see Gallery::build_gallery_table()}). * * The list items arrive already rendered (post-template is a dynamic block, so `$block_content` * holds the final ``), so this renderer never re-runs the query. Each item's * image is extracted and rebuilt as a clean, responsive `` sitting directly in its grid cell — * the same shape the Gallery renderer emits. This is deliberate: the images WordPress renders inside * a post-template `
  • ` are wrapped in fixed-width, auto-layout tables (``) that * were never sized for email, and a nested `width: 100%` image inside them collapses to a few pixels * in Gmail (the width has no resolvable basis). Hoisting the image into the grid cell gives it a * definite basis so it fills its column and scales down on mobile. An item with no image falls back * to its original markup untouched (text content stacks correctly on its own). */ class Post_Template extends Abstract_Block_Renderer { /** * Upper bound on grid columns, matching the maximum the core grid layout control allows (its * Columns range control tops out at 16). Honors any column count an author can pick in the editor, * while still bounding an out-of-range hand-edited value so it can't emit a runaway number of cells. */ private const MAX_COLUMNS = 16; /** * Per-cell padding (px) that stands in for the grid's `gap` between items. */ private const CELL_PADDING = 8; /** * Responsive image style applied to every rebuilt grid image. `width: 100%` fills the column, * `max-width: 100%` lets it scale down on narrow viewports, and `height: auto` keeps the ratio. * The explicit `width` attribute (set alongside this) is the Outlook fallback, since Outlook * ignores `max-width`. */ private const IMAGE_STYLE = 'border: 0; line-height: 100%; width: 100%; max-width: 100%; height: auto; display: block;'; /** * Renders the post-template block content using a table-based grid layout. * * @param string $block_content Block content. * @param array $parsed_block Parsed block. * @param Rendering_Context $rendering_context Rendering context. * @return string */ 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 ); } /** * Locate the post-template list within the rendered content. * * The list is matched by its `wp-block-post-template` class rather than by being the first * `