<% // determine columns and chunk rows const cols = (buttons && buttons.COLS) || ['']; const numCols = Math.max(1, cols.length); const rowsFlat = (buttons && buttons.ROWS) || []; const chunks = []; for (let i = 0; i < rowsFlat.length; i += numCols) { const slice = rowsFlat.slice(i, i + numCols); // pad short slice with empty objects so layout stays consistent while (slice.length < numCols) slice.push({}); chunks.push(slice); } %>
<% for (let c = 0; c < numCols; c++) { %> <% } %> <% chunks.forEach((row) => { %> <% for (let c = 0; c < numCols; c++) { const cell = row[c] || {}; const isBlank = Object.keys(cell).length === 0; %> <% } %> <% }); %>

<%= cols[c] || '' %>

<% if (isBlank) { %> <% } else { const ctx = cell.context || {}; %> <% } %>