Answers.Body: <p>Since there are a set number of quarters you can probably just collect the entries in a temporary array. Then use those to build your tables.</p>
  
  <pre><code>{% set quarter1 = [] %}
  {% set quarter2 = [] %}
  {% set quarter3 = [] %}
  
  {% for row in entry.courses %}
  
      {% if row.classQuarter == 1 %}
          {% set quarter1 = quarter1|merge([row]) %}
      {% endif %}
  
      {% if row.classQuarter == 2 %}
          {% set quarter2 = quarter2|merge([row]) %}
      {% endif %}
  
      {% if row.classQuarter == 3 %}
          {% set quarter3 = quarter3|merge([row]) %}
      {% endif %}
  
  {% endfor %}
  
  &lt;table&gt;
      {% for row in quarter1 %}
          &lt;tr&gt;
              &lt;td&gt;{{ row.courseNumber }}&lt;/td&gt;
              &lt;td&gt;{{ row.courseDescription }}&lt;/td&gt;
          &lt;/tr&gt;    
      {% endfor %}
  &lt;/table&gt;
  
  &lt;table&gt;
      {% for row in quarter2 %}
          &lt;tr&gt;
              &lt;td&gt;{{ row.courseNumber }}&lt;/td&gt;
              &lt;td&gt;{{ row.courseDescription }}&lt;/td&gt;
          &lt;/tr&gt;    
      {% endfor %}
  &lt;/table&gt;
  
  &lt;table&gt;
      {% for row in quarter3 %}
          &lt;tr&gt;
              &lt;td&gt;{{ row.courseNumber }}&lt;/td&gt;
              &lt;td&gt;{{ row.courseDescription }}&lt;/td&gt;
          &lt;/tr&gt;    
      {% endfor %}
  &lt;/table&gt;
  </code></pre>
  
  <p>You could also add an 'if' clause in the 'for...in' loop. See the twig docs on <a href="http://twig.sensiolabs.org/doc/tags/for.html#adding-a-condition" rel="nofollow">adding a condition</a> for more info.</p>
  
  <pre><code>&lt;table&gt;
      {% for row in entry.courses if row.classQuarter == 1 %}
          &lt;tr&gt;
              &lt;td&gt;{{ row.courseNumber }}&lt;/td&gt;
              &lt;td&gt;{{ row.courseDescription }}&lt;/td&gt;
          &lt;/tr&gt; 
      {% endfor %}
  &lt;/table&gt;
  &lt;table&gt;
      {% for row in entry.courses if row.classQuarter == 2 %}
          &lt;tr&gt;
              &lt;td&gt;{{ row.courseNumber }}&lt;/td&gt;
              &lt;td&gt;{{ row.courseDescription }}&lt;/td&gt;
          &lt;/tr&gt; 
      {% endfor %}
  &lt;/table&gt;
  &lt;table&gt;
      {% for row in entry.courses if row.classQuarter == 3 %}
          &lt;tr&gt;
              &lt;td&gt;{{ row.courseNumber }}&lt;/td&gt;
              &lt;td&gt;{{ row.courseDescription }}&lt;/td&gt;
          &lt;/tr&gt; 
      {% endfor %}
  &lt;/table&gt;
  </code></pre>
  
  <p>And could also probably condense that using the <a href="http://twig.sensiolabs.org/doc/functions/range.html" rel="nofollow">range</a> shortcut.</p>
  
  <pre><code>{% for quarter in 1..4 %}
      &lt;table&gt;
          {% for row in entry.courses if row.classQuarter == quarter %}
              &lt;tr&gt;
                  &lt;td&gt;{{ row.courseNumber }}&lt;/td&gt;
                  &lt;td&gt;{{ row.courseDescription }}&lt;/td&gt;
              &lt;/tr&gt; 
          {% endfor %}
      &lt;/table&gt;
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-13T00:37:00.983Z
Answers.LastActivityDate: 2015-01-13T01:03:02.003Z
Answers.LastEditDate: 2015-01-13T01:03:02.003Z
Answers.UserDisplayName: Douglas McDonald
Body: <p>Here's an example, I have three columns in a table: ClassQuarter, Course No, Description.</p>
  
  <p>I would like to output rows only with ClassQuarter == '1' in a HTML table, then output rows where ClassQuarter == '2' in another table, then output rows where ClassQuarter == '3' in another table.</p>
  
  <p>Am I able to output rows with a condition for the first column?</p>
  
Tags: <templating><table-field>
Title: Is there a way to output certain rows (or filter) from a table?
ThreadText: # Is there a way to output certain rows (or filter) from a table?
  
  (Asked by: username_0 on 2015-01-13)
  
  Here's an example, I have three columns in a table: ClassQuarter, Course No, Description.
  
  I would like to output rows only with ClassQuarter == '1' in a HTML table, then output rows where ClassQuarter == '2' in another table, then output rows where ClassQuarter == '3' in another table.
  
  Am I able to output rows with a condition for the first column?
  
  **Tags:** templating, table-field
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-01-13. Score: 2 | Accepted answer
  
  Since there are a set number of quarters you can probably just collect the entries in a temporary array. Then use those to build your tables.
  
  ```
  {% set quarter1 = [] %}
  {% set quarter2 = [] %}
  {% set quarter3 = [] %}
  
  {% for row in entry.courses %}
  
      {% if row.classQuarter == 1 %}
          {% set quarter1 = quarter1|merge([row]) %}
      {% endif %}
  
      {% if row.classQuarter == 2 %}
          {% set quarter2 = quarter2|merge([row]) %}
      {% endif %}
  
      {% if row.classQuarter == 3 %}
          {% set quarter3 = quarter3|merge([row]) %}
      {% endif %}
  
  {% endfor %}
  
  <table>
      {% for row in quarter1 %}
          <tr>
              <td>{{ row.courseNumber }}</td>
              <td>{{ row.courseDescription }}</td>
          </tr>    
      {% endfor %}
  </table>
  
  <table>
      {% for row in quarter2 %}
          <tr>
              <td>{{ row.courseNumber }}</td>
              <td>{{ row.courseDescription }}</td>
          </tr>    
      {% endfor %}
  </table>
  
  <table>
      {% for row in quarter3 %}
          <tr>
              <td>{{ row.courseNumber }}</td>
              <td>{{ row.courseDescription }}</td>
          </tr>    
      {% endfor %}
  </table>
  
  ```
  
  You could also add an 'if' clause in the 'for...in' loop. See the twig docs on [adding a condition](http://twig.sensiolabs.org/doc/tags/for.html#adding-a-condition) for more info.
  
  ```
  <table>
      {% for row in entry.courses if row.classQuarter == 1 %}
          <tr>
              <td>{{ row.courseNumber }}</td>
              <td>{{ row.courseDescription }}</td>
          </tr> 
      {% endfor %}
  </table>
  <table>
      {% for row in entry.courses if row.classQuarter == 2 %}
          <tr>
              <td>{{ row.courseNumber }}</td>
              <td>{{ row.courseDescription }}</td>
          </tr> 
      {% endfor %}
  </table>
  <table>
      {% for row in entry.courses if row.classQuarter == 3 %}
          <tr>
              <td>{{ row.courseNumber }}</td>
              <td>{{ row.courseDescription }}</td>
          </tr> 
      {% endfor %}
  </table>
  
  ```
  
  And could also probably condense that using the [range](http://twig.sensiolabs.org/doc/functions/range.html) shortcut.
  
  ```
  {% for quarter in 1..4 %}
      <table>
          {% for row in entry.courses if row.classQuarter == quarter %}
              <tr>
                  <td>{{ row.courseNumber }}</td>
                  <td>{{ row.courseDescription }}</td>
              </tr> 
          {% endfor %}
      </table>
  {% endfor %}
  
  ```
  
  
  ---
  
  