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


I've also attached a screenshot of my Matrix setup. Thanks so much in advance]1
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 %}
           &lt;p&gt;Do something else&lt;/p&gt;
       {% 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 % }
       &lt;p&gt;Fallback&lt;/p&gt;
{% endif %}


Another option is to check this little plugin: Store hours