<p>I forget who solved this for me! I think it was Michael van Dorth.</p>

<pre><code>&lt;div class="table-overflow content-row"&gt;
    &lt;table class="table {{ table_class }}"&gt;

      {# Caption #}
      {% if block.caption %}
        &lt;caption class="caption"&gt;{{ block.caption }}&lt;/caption&gt;
      {% endif %}

      {# Setup #}
      {% set rows = block.contactTable.all() %}
      {% set phoneRows = 0 %}
      {% set emailRows = 0 %}
      {% set websiteRows = 0 %}

      {% for row in rows %}
        {% if row.phone != '' %}
          {% set phoneRows = phoneRows + 1 %}
        {% endif %}
        {% if row.email != '' %}
          {% set emailRows = emailRows + 1 %}
        {% endif %}
        {% if row.website != '' %}
          {% set websiteRows = websiteRows + 1 %}
        {% endif %}
      {% endfor %}

      {# Headings #}
      &lt;thead class="thead_class"&gt;
        &lt;tr&gt;
          &lt;th scope="col"&gt;Name&lt;/th&gt;
          {% if phoneRows &gt; 0 %}&lt;th scope="col"&gt;Phone&lt;/th&gt;{% endif %}
          {% if emailRows &gt; 0 %}&lt;th scope="col"&gt;Email&lt;/th&gt;{% endif %}
          {% if websiteRows &gt; 0 %}&lt;th scope="col"&gt;Website&lt;/th&gt;{% endif %}
        &lt;/tr&gt;
      &lt;/thead&gt;

      {# Body #}
      &lt;tbody class="tbody_class"&gt;
        {% for row in block.contactTable.all() %}

          &lt;tr&gt;

            &lt;th scope="row"&gt;{{ row.contactName }}&lt;/th&gt;

            {% if phoneRows &gt; 0 %}
              &lt;td&gt;{% if row.phone|length %}{{ row.phone.link }}{% endif %}&lt;/td&gt;
            {% endif %}

            {% if emailRows &gt; 0 %}
              &lt;td&gt;{% if row.email|length %}
                &lt;a class="btn" href="{{ row.email.url }}" aria-label="{{ row.contactName ~ ' email' }}"&gt;Email&lt;/a&gt;
              {% endif %}&lt;/td&gt;
            {% endif %}

            {% if websiteRows &gt; 0 %}
              &lt;td&gt;{% if row.website|length %}
                &lt;a class="btn" href="{{ row.website.url }}" aria-label="{{ row.contactName ~ ' website' }}"&gt;Website&lt;/a&gt;
              {% endif %}&lt;/td&gt;
            {% endif %}

          &lt;/tr&gt;

        {% endfor %}
      &lt;/tbody&gt;

    &lt;/table&gt;
  &lt;/div&gt;
</code></pre>

CC BY-SA 4.0
2019-09-04T13:43:46.950Z
2019-09-04T13:43:46.950Z
Katie Fritz
<p>I have a "contact table" SuperTable with columns for Name, Phone, Email, and Website. In the template, I'm displaying the data as a table.</p>

<p>I only want to generate table columns if a column has data. For example, if there are no Phone Numbers included, I don't want a Phone column. If even one row has a phone number, I do want to include that column.</p>

<p>How do I create a conditional to check whether a SuperTable column has data in it?</p>

<p>This might be related to <a href="https://craftcms.stackexchange.com/questions/30373/querying-a-supertable-field">Querying a supertable field</a>.</p>

<craft3><plugin-supertable><table>
How to tell whether a SuperTable column has data or is empty?
# How to tell whether a SuperTable column has data or is empty?

(Asked by: username_0 on 2019-05-17)

I have a "contact table" SuperTable with columns for Name, Phone, Email, and Website. In the template, I'm displaying the data as a table.

I only want to generate table columns if a column has data. For example, if there are no Phone Numbers included, I don't want a Phone column. If even one row has a phone number, I do want to include that column.

How do I create a conditional to check whether a SuperTable column has data in it?

This might be related to [Querying a supertable field](https://craftcms.stackexchange.com/questions/30373/querying-a-supertable-field).

**Tags:** craft3, plugin-supertable, table

---

## 1 answers

### Answer by username_0 on 2019-09-04. Score: 1 | Accepted answer

I forget who solved this for me! I think it was Michael van Dorth.

    

      {# Caption #}
      {% if block.caption %}
        {{ block.caption }}
      {% endif %}

      {# Setup #}
      {% set rows = block.contactTable.all() %}
      {% set phoneRows = 0 %}
      {% set emailRows = 0 %}
      {% set websiteRows = 0 %}

      {% for row in rows %}
        {% if row.phone != '' %}
          {% set phoneRows = phoneRows + 1 %}
        {% endif %}
        {% if row.email != '' %}
          {% set emailRows = emailRows + 1 %}
        {% endif %}
        {% if row.website != '' %}
          {% set websiteRows = websiteRows + 1 %}
        {% endif %}
      {% endfor %}

      {# Headings #}
      
        
          Name
          {% if phoneRows > 0 %}Phone{% endif %}
          {% if emailRows > 0 %}Email{% endif %}
          {% if websiteRows > 0 %}Website{% endif %}
        
      

      {# Body #}
      
        {% for row in block.contactTable.all() %}

          

            {{ row.contactName }}

            {% if phoneRows > 0 %}
              {% if row.phone|length %}{{ row.phone.link }}{% endif %}
            {% endif %}

            {% if emailRows > 0 %}
              {% if row.email|length %}
                Email
              {% endif %}
            {% endif %}

            {% if websiteRows > 0 %}
              {% if row.website|length %}
                Website
              {% endif %}
            {% endif %}

          

        {% endfor %}


---

