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

CC BY-SA 3.0
2017-01-24T04:47:41.700Z
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!
Adam
CC BY-SA 3.0
2017-01-24T08:06:45.227Z
You can always mark my answer as correct @Adam ;-)
Jan_dh
CC BY-SA 3.0
2017-01-16T21:44:54.960Z
2017-01-16T21:44:54.960Z
Jan_dh
<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>

<matrix><entry><conditional>
Conditional check if Matrix block field is empty (no content)
# 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 %} 

  
    
      {% for block in entry.hours %}
      
        {{ block.days }}
        {{ block.times }}
      
      {% endfor %}
    
  

{% else %} 
  We're still trying to track down hours.
{% endif %}

I've also attached a screenshot of my Matrix setup. Thanks so much in advance]1

**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 %}
           Do something else
       {% 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 . 
Then you could just do
{% for row in entry.tableHandle %}
   {% if row|length %}
       {{row.text}}
   {% else % }
       Fallback
{% endif %}

Another option is to check this little plugin: Store hours

> **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 @Adam ;-)  

---

