[%- 
  USE Perl;
  USE rounded    = format('%.0f');
  SET num_items  = items.size;
  IF num_items <= 10;
    SET num_cols = 2;
  ELSE;
    SET num_cols = Perl.sqrt( num_items );
    SET num_cols = num_cols + 0.5;
    SET num_cols = rounded( num_cols );
  END;
  SET num_per_col = num_items / num_cols;
  IF num_per_col.match('\d+[.]\d+');
    SET num_per_col = num_per_col + 0.5;
    SET num_per_col = rounded( num_per_col );
  END;
  SET num_cells   = num_cols * num_per_col - 1;
-%]
[% IF num_items == 1 %]
  [% items.0 %]
[% ELSE %]
<table width="100%" class="invisible">
  [% FOREACH i IN [ 0 .. num_cells ] %]
      [% IF i % num_cols == 0 %]<tr>[% END %]
        <td>[% IF i < num_items; items.$i; ELSE; '&nbsp;'; END %]</td>
      [% IF ( i + 1 ) % num_cols == 0 %]</tr>[% END %]
  [% END %]
</table>
[% END %]
