Answers.Body: <p>I'm assuming your matrix field is not called hours? Because in your current code you are handeling it like it is.</p>
  
  <p>I think this should work</p>
  
  <pre><code>   {% for block in entry.matrixfieldHandle %}
         {% if block|length %}
             {{block.days}} - {{block.time}}
         {% else %}
             &lt;p&gt;Do something else&lt;/p&gt;
         {% endif% }
      {% endfor %}
  </code></pre>
  
  <p>In your code you want to loop over all the different entries (blocks) within the matrix. If you want to add other types you can easely check for hours like so:</p>
  
  <pre><code>{% if block.type == "hours" %}
     do stuff
  {% elseif block.type == "anotherblocktype" %}
     ...
  </code></pre>
  
  <p>However. Since you only use one type of content I'm not sure if a matrix is the best solution. You could easely put this in a table or <a href="https://github.com/engram-design/SuperTable" rel="nofollow noreferrer">supertable</a> . </p>
  
  <p>Then you could just do</p>
  
  <pre><code>{% for row in entry.tableHandle %}
     {% if row|length %}
         {{row.text}}
     {% else % }
         &lt;p&gt;Fallback&lt;/p&gt;
  {% endif %}
  </code></pre>
  
  <p>Another option is to check this little plugin: <a href="https://github.com/pixelandtonic/StoreHours" rel="nofollow noreferrer">Store hours</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-24T04:47:41.700Z
Answers.Text: Thanks so much Jan! Your suggestions worked like a charm—however, you're correct that a matrix was not the best solution. I'd simply gotten so used to using it, I forgot about all my other options. A table worked great and simplified things quite a bit. Thanks again!
Answers.UserDisplayName: Adam
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-24T08:06:45.227Z
Answers.Text: You can always mark my answer as correct @Adam ;-)
Answers.UserDisplayName: Jan_dh
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-01-16T21:44:54.960Z
Answers.LastActivityDate: 2017-01-16T21:44:54.960Z
Answers.UserDisplayName: Jan_dh
Body: <p>I'm having a difficult time with what seems like a fairly straightforward problem:</p>
  
  <p>I'm listing businesses and their related hours of operation (days/times). I'd like to set up a conditional statement that checks if a Matrix field has content—if so, display hours. If not, display message. My code is as follows:</p>
  
  <pre><code>{% if entry.hours.block('days')|length %} &lt;!-- I am trying to check Matrix field "days" is empty (content exists) --&gt;
  &lt;div class="entry__hours"&gt;
    &lt;table&gt;
      &lt;tbody&gt;
        {% for block in entry.hours %}&lt;!-- Loop through days/times...this part works fine --&gt;
        &lt;tr&gt;
          &lt;td class="entry__days"&gt;{{ block.days }}&lt;/td&gt;
          &lt;td class="entry__times"&gt;{{ block.times }}&lt;/td&gt;
        &lt;/tr&gt;
        {% endfor %}
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
  {% else %} &lt;!-- This part does not show up if Matrix field "days" is empty --&gt;
    &lt;p&gt;We're still trying to track down hours.&lt;/p&gt;
  {% endif %}
  </code></pre>
  
  <p>I've also attached a screenshot of my Matrix setup. Thanks so much in advance<img src="https://i.sstatic.net/2cQ5z.png" alt="![enter image description here">]<a href="https://i.sstatic.net/2cQ5z.png" rel="nofollow noreferrer">1</a></p>
  
Tags: <matrix><entry><conditional>
Title: Conditional check if Matrix block field is empty (no content)
ThreadText: # Conditional check if Matrix block field is empty (no content)
  
  (Asked by: username_0 on 2017-01-16)
  
  I'm having a difficult time with what seems like a fairly straightforward problem:
  
  I'm listing businesses and their related hours of operation (days/times). I'd like to set up a conditional statement that checks if a Matrix field has content—if so, display hours. If not, display message. My code is as follows:
  
  ```
  {% if entry.hours.block('days')|length %} <!-- I am trying to check Matrix field "days" is empty (content exists) -->
  <div class="entry__hours">
    <table>
      <tbody>
        {% for block in entry.hours %}<!-- Loop through days/times...this part works fine -->
        <tr>
          <td class="entry__days">{{ block.days }}</td>
          <td class="entry__times">{{ block.times }}</td>
        </tr>
        {% endfor %}
      </tbody>
    </table>
  </div>
  {% else %} <!-- This part does not show up if Matrix field "days" is empty -->
    <p>We're still trying to track down hours.</p>
  {% endif %}
  
  ```
  
  I've also attached a screenshot of my Matrix setup. Thanks so much in advance![![enter image description here](https://i.sstatic.net/2cQ5z.png)][1](https://i.sstatic.net/2cQ5z.png)
  
  **Tags:** matrix, entry, conditional
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-01-16. Score: 3
  
  I'm assuming your matrix field is not called hours? Because in your current code you are handeling it like it is.
  
  I think this should work
  
  ```
     {% for block in entry.matrixfieldHandle %}
         {% if block|length %}
             {{block.days}} - {{block.time}}
         {% else %}
             <p>Do something else</p>
         {% endif% }
      {% endfor %}
  
  ```
  
  In your code you want to loop over all the different entries (blocks) within the matrix. If you want to add other types you can easely check for hours like so:
  
  ```
  {% if block.type == "hours" %}
     do stuff
  {% elseif block.type == "anotherblocktype" %}
     ...
  
  ```
  
  However. Since you only use one type of content I'm not sure if a matrix is the best solution. You could easely put this in a table or [supertable](https://github.com/engram-design/SuperTable) .
  
  Then you could just do
  
  ```
  {% for row in entry.tableHandle %}
     {% if row|length %}
         {{row.text}}
     {% else % }
         <p>Fallback</p>
  {% endif %}
  
  ```
  
  Another option is to check this little plugin: [Store hours](https://github.com/pixelandtonic/StoreHours)
  
  > **Comments:**
  > **username_0**: Thanks so much Jan! Your suggestions worked like a charm—however, you're correct that a matrix was not the best solution. I'd simply gotten so used to using it, I forgot about all my other options. A table worked great and simplified things quite a bit. Thanks again!  
  > **username_1**: You can always mark my answer as correct @username_0 ;-)  
  
  ---
  
  