Answers.Body: <p>This should do it for a text field:</p>
  
  <pre><code>craft.entries.section('aboutus').textField(':empty:')|length
  </code></pre>
  
  <p>To see if a Matrix field has any blocks, it's not as pretty.  There's probably a better way, but it's all I can think of at the moment:</p>
  
  <pre><code>{% set entries = craft.entries.section('news') %}
  
  {% set validEntries = [] %}
  
  {% for entry in entries %}
      {% if entry.matrixField|length %}
          {% set validEntries = valid|merge([entry]) %}
      {% endif %}
  {% endfor %}
  </code></pre>
  
  <p><code>validEntries</code> is now an array of entries that have at least one block.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-15T22:34:51.310Z
Answers.Text: thanks! But now I have a matrix. How I get the real length here?
Answers.UserDisplayName: Jonathan Schiffner
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-15T23:18:14.870Z
Answers.Text: So `textField` is in a Matrix block inside of a Matrix field? Can you update the question with the name of the block and Matrix field?
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-15T23:23:28.267Z
Answers.Text: No, for the `textField` your version works fine. But now I have the same problem with a Matrix Block. But wait. I will update the question
Answers.UserDisplayName: Jonathan Schiffner
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-20T15:41:43.753Z
Answers.Text: And is there a way to check if an `lightswitch Field` is on or not?
Answers.UserDisplayName: Jonathan Schiffner
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-15T16:55:45.660Z
Answers.LastActivityDate: 2016-03-16T00:27:49.750Z
Answers.LastEditDate: 2016-03-16T00:27:49.750Z
Answers.UserDisplayName: Brad Bell
Body: <p>Some links in the menu should only be shown if the textfield is not empty. For example:</p>
  
  <pre><code>{% if craft.entries.section('aboutus').textField|length == 0 %} style="display: none;" {% endif %}.
  </code></pre>
  
  <p>But <code>craft.entries.section('aboutus').textField|length</code> always returns <code>1</code>. I also tried <code>is empty</code>. </p>
  
  <p>So, how I get the real length of this textfield? </p>
  
  <p>And I have the same problem with a matrix. How can I check if the Matrix field has any blocks?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-03-15T23:27:34.117Z
Comments.Text: "How can I check if the matrix is empty or not?" Does that mean you want to see if your Matrix field has any blocks? Or you want to see if a particular field inside of a Matrix block is empty?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-03-15T23:33:53.720Z
Comments.Text: And want to see if the Matrix field has any blocks
Comments.UserDisplayName: Jonathan Schiffner
Tags: <templating>
Title: Check length of textfield in header file
ThreadText: # Check length of textfield in header file
  
  (Asked by: username_0 on 2016-03-15)
  
  Some links in the menu should only be shown if the textfield is not empty. For example:
  
  ```
  {% if craft.entries.section('aboutus').textField|length == 0 %} style="display: none;" {% endif %}.
  
  ```
  
  But `craft.entries.section('aboutus').textField|length` always returns `1`. I also tried `is empty`.
  
  So, how I get the real length of this textfield?
  
  And I have the same problem with a matrix. How can I check if the Matrix field has any blocks?
  
  **Tags:** templating
  
  > **Comments:**
  > **username_1**: "How can I check if the matrix is empty or not?" Does that mean you want to see if your Matrix field has any blocks? Or you want to see if a particular field inside of a Matrix block is empty?  
  > **username_0**: And want to see if the Matrix field has any blocks  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-03-15. Score: 2 | Accepted answer
  
  This should do it for a text field:
  
  ```
  craft.entries.section('aboutus').textField(':empty:')|length
  
  ```
  
  To see if a Matrix field has any blocks, it's not as pretty. There's probably a better way, but it's all I can think of at the moment:
  
  ```
  {% set entries = craft.entries.section('news') %}
  
  {% set validEntries = [] %}
  
  {% for entry in entries %}
      {% if entry.matrixField|length %}
          {% set validEntries = valid|merge([entry]) %}
      {% endif %}
  {% endfor %}
  
  ```
  
  `validEntries` is now an array of entries that have at least one block.
  
  > **Comments:**
  > **username_0**: thanks! But now I have a matrix. How I get the real length here?  
  > **username_1**: So `textField` is in a Matrix block inside of a Matrix field? Can you update the question with the name of the block and Matrix field?  
  > **username_0**: No, for the `textField` your version works fine. But now I have the same problem with a Matrix Block. But wait. I will update the question  
  > **username_0**: And is there a way to check if an `lightswitch Field` is on or not?  
  
  ---
  
  