title: Modulus (or lack thereof) in Ruby's Liquid templating engine
body: <p>I'm working on a Jekyll site and am trying to output three column divs nested in a row div. <a href="http://wiki.github.com/tobi/liquid/liquid-for-designers" rel="nofollow noreferrer" title="Liquid for Designers - liquid - GitHub">Liquid</a> makes this pretty easy with their <code>cycle</code> filter:</p>
  
  <pre><code>{% for p in site.categories.post %}
      {% cycle 'add rows': '&lt;div class="row"&gt;', nil, nil %}
          &lt;div class="column"&gt;
              &lt;a href="{{ p.url }}"&gt;{{ p.title }}&lt;/a&gt;
          &lt;/div&gt;
      {% cycle 'close rows': nil, nil, '&lt;/div&gt;' %}
  {% endfor %}
  </code></pre>
  
  <p>However, this only really works when there are 3, 6, 9, etc. posts. When the total number of posts is not a multiple of three, the <code>&lt;div class="row"&gt;</code> never gets closed--the for loop ends before the closing tag can be output as part of the <code>close rows</code> cycle.</p>
  
  <p>In Ruby, PHP, or any other language I could easily fix this with a modulus operator, so in addition to <code>close rows</code> cycle I would output <code>&lt;/div&gt;</code> when <code>if site.categories.size % 3 == 0</code>. However, Liquid, because it's a safe templating language, doesn't support the modulus. </p>
  
  <p>What else can I do to properly close <code>&lt;div class="row"&gt;</code> when the total number of posts is not a multiple of three?</p>