Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-09-04T13:43:46.950Z
Answers.LastActivityDate: 2019-09-04T13:43:46.950Z
Answers.UserDisplayName: Katie Fritz
Body: <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>
  
Tags: <craft3><plugin-supertable><table>
Title: How to tell whether a SuperTable column has data or is empty?
ThreadText: # 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.
  
  ```
  <div class="table-overflow content-row">
      <table class="table {{ table_class }}">
  
        {# Caption #}
        {% if block.caption %}
          <caption class="caption">{{ block.caption }}</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 #}
        <thead class="thead_class">
          <tr>
            <th scope="col">Name</th>
            {% if phoneRows > 0 %}<th scope="col">Phone</th>{% endif %}
            {% if emailRows > 0 %}<th scope="col">Email</th>{% endif %}
            {% if websiteRows > 0 %}<th scope="col">Website</th>{% endif %}
          </tr>
        </thead>
  
        {# Body #}
        <tbody class="tbody_class">
          {% for row in block.contactTable.all() %}
  
            <tr>
  
              <th scope="row">{{ row.contactName }}</th>
  
              {% if phoneRows > 0 %}
                <td>{% if row.phone|length %}{{ row.phone.link }}{% endif %}</td>
              {% endif %}
  
              {% if emailRows > 0 %}
                <td>{% if row.email|length %}
                  <a class="btn" href="{{ row.email.url }}" aria-label="{{ row.contactName ~ ' email' }}">Email</a>
                {% endif %}</td>
              {% endif %}
  
              {% if websiteRows > 0 %}
                <td>{% if row.website|length %}
                  <a class="btn" href="{{ row.website.url }}" aria-label="{{ row.contactName ~ ' website' }}">Website</a>
                {% endif %}</td>
              {% endif %}
  
            </tr>
  
          {% endfor %}
        </tbody>
  
      </table>
    </div>
  
  ```
  
  
  ---
  
  