This page last changed on Sep 30, 2011 by kristin.bradley@involver.com.

Creating Tables in SML

SML can create table rows and cells for you using the tablerow loop. The tablerow loop functions exactly like a for loop except that the outputs are built into a dynamically generated table instead of a list of item. It is ideal for displaying data sets and the tables generated can be styled with CSS. The number of columns and the total number of items in the table are controlled by attributes.

Basic Configuration

<table>
  {% tablerow item in items cols: 3 limit: 12 %}
    {{ item.variable }}
  {% endtablerow %}
</table>

Attributes

attribute type required description
cols integer yes Sets the number of columns for the table
limit integer no Sets the maximum number of items to display

Variables

variable description
tablerowloop.length length of the entire for loop
tablerowloop.index index of the current iteration
tablerowloop.index0 index of the current iteration (zero based)
tablerowloop.rindex how many items are still left?
tablerowloop.rindex0 how many items are still left? (zero based)
tablerowloop.first is this the first iteration?
tablerowloop.last is this the last iteration?
tablerowloop.col index of column in the current row
tablerowloop.col0 index of column in the current row (zero based)
tablerowloop.col_first is this the first column in the row?
tablerowloop.col_last is this the last column in the row?

Advanced code Sample

You can use if logic and the position variables to apply unique styles or customize content outputs for the first column (for instance).

<table>
 {% tablerow item in items cols: 3 %}
    {% if tablerowloop.col_first %}
      First column: {{ item.variable }}
    {% else %}
      Different column: {{ item.variable }}
    {% endif %}
  {% endtablerow %}
</table>
Document generated by Confluence on Feb 12, 2013 09:09