{# Title gets its own page so it doesn't steal height from the first grid. #}
{% if title %}
{{ title }}
{% endif %}
{# One table per logical gallery page. Height is set on each
(not
—
WeasyPrint ignores height on
) so content is explicitly bounded and
never fragments across pages. #}
{% for page in pages %}
{% for row in page.rows_data %}
{% for cell in row %}
{# cell_h_pt and img_h_pt are per-cell when optimize_packing is on,
otherwise uniform across the page. #}
{% set ch = cell.cell_h_pt if cell else page.cell_h_pt %}
{% if cell %}
{% if captions == 'above' and cell.caption %}