<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>

CC BY-SA 3.0
2015-01-13T00:37:00.983Z
2015-01-13T01:03:02.003Z
2015-01-13T01:03:02.003Z
Douglas McDonald
<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>

<templating><table-field>
Is there a way to output certain rows (or filter) from a table?
# 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 %}


    {% for row in quarter1 %}
        
            {{ row.courseNumber }}
            {{ row.courseDescription }}
            
    {% endfor %}



    {% for row in quarter2 %}
        
            {{ row.courseNumber }}
            {{ row.courseDescription }}
            
    {% endfor %}



    {% for row in quarter3 %}
        
            {{ row.courseNumber }}
            {{ row.courseDescription }}
            
    {% endfor %}


You could also add an 'if' clause in the 'for...in' loop. See the twig docs on adding a condition for more info.

    {% for row in entry.courses if row.classQuarter == 1 %}
        
            {{ row.courseNumber }}
            {{ row.courseDescription }}
         
    {% endfor %}


    {% for row in entry.courses if row.classQuarter == 2 %}
        
            {{ row.courseNumber }}
            {{ row.courseDescription }}
         
    {% endfor %}


    {% for row in entry.courses if row.classQuarter == 3 %}
        
            {{ row.courseNumber }}
            {{ row.courseDescription }}
         
    {% endfor %}


And could also probably condense that using the range shortcut.
{% for quarter in 1..4 %}
    
        {% for row in entry.courses if row.classQuarter == quarter %}
            
                {{ row.courseNumber }}
                {{ row.courseDescription }}
             
        {% endfor %}
    
{% endfor %}


---

