Answers.Body: <p>Thanks to Brad for asking me a question above, it made me realize I was checking for matrix fields and not the matrix block. My code is now working that I am checking for the correct element on the page.  </p>
  
  <p>Revised code:</p>
  
  <pre><code>{% if entry.modelIds|length == 1 %}
       I am link - {{block.modelId}} &lt;br&gt;
  {% else %}
       Not a Link - {{block.modelId}}&lt;br&gt;
  {% endif %}
  </code></pre>
  
  <p>Thanks Brad for the help! </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-03-04T15:22:58.683Z
Answers.LastActivityDate: 2016-03-04T15:22:58.683Z
Answers.UserDisplayName: johnHoysa
Body: <p>I have a Matrix field which contains a bunch of blocks. If only one matrix field is present in the entry I need it to show a message. If more then one matrix field show an other message.</p>
  
  <p>Below is my current code.</p>
  
  <pre><code>{% for block in entry.modelIds.limit(1) %}
      {% if block.modelId|length == 1 %}
          I am link - {{block.modelId}} &lt;br&gt;
      {% else %}
          Not a Link - {{block.modelId}}&lt;br&gt;
      {% endif %}
  {% endfor %}
  </code></pre>
  
  <p>Any help would be appreciated. I have tried a few different approaches and am just stumped. </p>
  
  <p>Thanks!</p>
  
  <p>Edit: adding image of fields.
  <a href="https://i.sstatic.net/aQfs5.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/aQfs5.png" alt="enter image description here"></a></p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-03-03T20:13:16.903Z
Comments.Text: "If only one matrix field is present" Do you mean "matrix block" there? I assume `modelIds` is the Matrix field, what type of field is `modelId`?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-03-03T21:07:11.070Z
Comments.Text: modelIds is the matrix field name.  block.modelId is a plain text field within modelIds. I hope this helps.
Comments.UserDisplayName: johnHoysa
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-03-04T00:06:38.573Z
Comments.Text: So correct me if I'm wrong: if a Matrix block has 1 field show message A, if it has more than one field show message B?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-03-04T14:54:03.790Z
Comments.Text: That is/was correct. Now that I am thinking about it, what I want to check for is if there is only one modelIds per entry not individual modelId. I need to update my example code! Thanks for helping me figure out that I was testing for the wrong element. Update coming soon.
Comments.UserDisplayName: johnHoysa
Tags: <matrix><conditional>
Title: If only one Matrix block show this, for more then one block show that
ThreadText: # If only one Matrix block show this, for more then one block show that
  
  (Asked by: username_0 on 2016-03-03)
  
  I have a Matrix field which contains a bunch of blocks. If only one matrix field is present in the entry I need it to show a message. If more then one matrix field show an other message.
  
  Below is my current code.
  
  ```
  {% for block in entry.modelIds.limit(1) %}
      {% if block.modelId|length == 1 %}
          I am link - {{block.modelId}} <br>
      {% else %}
          Not a Link - {{block.modelId}}<br>
      {% endif %}
  {% endfor %}
  
  ```
  
  Any help would be appreciated. I have tried a few different approaches and am just stumped.
  
  Thanks!
  
  Edit: adding image of fields.
  [![enter image description here](https://i.sstatic.net/aQfs5.png)](https://i.sstatic.net/aQfs5.png)
  
  **Tags:** matrix, conditional
  
  > **Comments:**
  > **username_1**: "If only one matrix field is present" Do you mean "matrix block" there? I assume `modelIds` is the Matrix field, what type of field is `modelId`?  
  > **username_0**: modelIds is the matrix field name.  block.modelId is a plain text field within modelIds. I hope this helps.  
  > **username_1**: So correct me if I'm wrong: if a Matrix block has 1 field show message A, if it has more than one field show message B?  
  > **username_0**: That is/was correct. Now that I am thinking about it, what I want to check for is if there is only one modelIds per entry not individual modelId. I need to update my example code! Thanks for helping me figure out that I was testing for the wrong element. Update coming soon.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2016-03-04. Score: 4 | Accepted answer
  
  Thanks to username_1 for asking me a question above, it made me realize I was checking for matrix fields and not the matrix block. My code is now working that I am checking for the correct element on the page.
  
  Revised code:
  
  ```
  {% if entry.modelIds|length == 1 %}
       I am link - {{block.modelId}} <br>
  {% else %}
       Not a Link - {{block.modelId}}<br>
  {% endif %}
  
  ```
  
  Thanks username_1 for the help!
  
  
  ---
  
  