<% // buttons is provided to this template const numCols = (buttons && buttons.COLS && buttons.COLS.length) || 1; const colWidth = (12 / numCols) >= 1 ? Math.floor(12 / numCols) : null; // chunk the flat ROWS array into logical rows of numCols items const chunks = []; for (let i = 0; i < (buttons.ROWS || []).length; i += numCols) { chunks.push((buttons.ROWS || []).slice(i, i + numCols)); } %>
<% for (let c = 0; c < numCols; c++) { %>
<%= buttons.COLS[c] || '' %>
<% } %>
<% chunks.forEach(function(row) { %>
<% for (let c = 0; c < numCols; c++) { const cell = row[c]; const isEmpty = !cell || Object.keys(cell).length === 0; const colClass = '<%= colWidth ? "col-' + colWidth + '" : "col" %>'; // placeholder for layout below %>
<% if (isEmpty) { %>
<% } else { // build data attributes from context if present const ctx = cell.context || {}; const dataAttrs = []; if (ctx.context) dataAttrs.push('data-context="' + ctx.context + '"'); if (ctx.timeout) dataAttrs.push('data-timeout="' + ctx.timeout + '"'); if (ctx.cid) dataAttrs.push('data-cid="' + ctx.cid + '"'); if (ctx.dial) dataAttrs.push('data-dial="' + ctx.dial + '"'); %> <% } %>
<% } %>
<% }); %>