Answers.Body: <p>You can use <code>{% if block.stepAccordionContent|length  %}...{% endif %}</code> to test if any rows are defined in your table field.</p>
  
  <p>Note: When you create a table field it will have an empty row defined under 'Default Values', which should be removed; otherwise all new instances of the table will have an empty row defined by default causing <code>block.stepAccordionContent|length</code> to return 1, instead of 0 as expected.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-06T22:19:06.370Z
Answers.Text: I'd also make sure you're looking at the correct `fellowshipStep` block since there could be multiple ones on the entry.
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-06T23:47:56.197Z
Answers.Text: My Test1: showed '1' for each, every 'foo' showed up, and in my entry with stepAccordionContent, Test1 showed '5' and the `accordion-selection` div, along with foo's
Answers.UserDisplayName: Nick
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-07T00:21:39.817Z
Answers.Text: I think I may have figured out your problem. In the table field settings in your matrix field, there is something called 'Default Values'. I would guess that you have one empty row defined, such that when you create a new matrix block, by default it has one empty row in it; thus when you run your test you get 1 for length, even though it looks empty. If you actually delete the empty row I would guess that it returns zero as expected. Go into your settings and delete that extra row from the 'Default Values', and the problem should go away.
Answers.UserDisplayName: Douglas McDonald
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-07T00:26:40.780Z
Answers.Text: @DouglasMcDonald I did have an empty row as a default value! Once I deleted this from the field settings, then went and deleted it for each entry already created, it worked!!!!! Bravo bravo!!!!
Answers.UserDisplayName: Nick
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-07T00:26:59.253Z
Answers.Text: You should add this as an answer!
Answers.UserDisplayName: Nick
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-07T01:28:38.207Z
Answers.Text: Great! whew. I updated the answer and deleted all my comments to help clean this up a bit.
Answers.UserDisplayName: Douglas McDonald
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-06T22:13:13.527Z
Answers.LastActivityDate: 2015-01-07T01:26:07.343Z
Answers.LastEditDate: 2015-01-07T01:26:07.343Z
Answers.UserDisplayName: Douglas McDonald
Body: <p>I want to see if a certain field exists in a block of a matrix. Here is my code.</p>
  
  <pre><code>{% for block in entry.someStepContainer %}
    &lt;div class="each-step"&gt;
  
      {% if block.type == "someStep" %}
        &lt;div class="step-number"&gt;&lt;span&gt;{{loop.index}}&lt;/span&gt;&lt;/div&gt;
        &lt;h3 class="step-title"&gt;{{block.stepTitle}}&lt;/h3&gt;
        &lt;div class="step-description"&gt;{{block.stepDescription}}&lt;/div&gt;
  
        &lt;! -- this is part I'm trying to fix --&gt;
  
        {% if block.stepAccordionContent %}
          &lt;div class="accordion-section"&gt;
            {% for row in block.stepAccordionContent %}
              &lt;h3 class="accordion-control"&gt;{{row.accordionTitle}}&lt;/h3&gt;
              &lt;p class="accordion-content" style="display: none;"&gt;{{row.accordionContent}}&lt;/p&gt;
            {% endfor %}
          &lt;/div&gt;
        {% endif %}
  
  
        &lt;!-- end part --&gt;
  
      {% endif %}
  
    &lt;/div&gt;
  {% endfor %} 
  </code></pre>
  
  <p>I've tried using:</p>
  
  <pre><code>{% if block.stepAccordionContent | length %}
  </code></pre>
  
  <p>But this still yields an empty</p>
  
  <pre><code>&lt;div class="accordion-section"&gt;
  </code></pre>
  
  <p><code>stepAccordionContent</code> is a table.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-01-06T00:50:22.900Z
Comments.Text: You say your checking if a Matrix block exists, but it looks like you're checking if a field inside of a block has any data.  Can you clarify what `stepAccordionContent` is?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-01-06T16:12:11.060Z
Comments.Text: @DouglasMcDonald printing `{{block.stepAccordionContent|length}}` gives me `0`.
Comments.UserDisplayName: Nick
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-01-06T16:14:57.657Z
Comments.Text: @BradBell you're right. I have a matrix that is `someStepsContainer` with one block `someStep` and three fields, one of them being `stepAccordionContent` which is a table.
Comments.UserDisplayName: Nick
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-01-06T16:21:09.197Z
Comments.Text: @BradBell `stepAccordionContent` is a table
Comments.UserDisplayName: Nick
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-01-06T17:16:02.097Z
Comments.Text: @DouglasMcDonald I was expecting if {%if block.stepAccordionContent|length%} returns 0, nothing inside the conditional would show. Instead, all content is showing (empty `h3` and `p`)
Comments.UserDisplayName: Nick
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-01-06T17:24:24.390Z
Comments.Text: @DouglasMcDonald doesn't work there either. I'm wondering if it's just checking for the presence of that field, in which case, it's always there, though it may be empty (which it is not checking for)
Comments.UserDisplayName: Nick
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-01-06T17:26:09.967Z
Comments.Text: @DouglasMcDonald are you asking if I've cleared my cache recently? (Sorry, not sure if "using `cache`" is something Craft-specific)
Comments.UserDisplayName: Nick
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-01-06T17:34:14.477Z
Comments.Text: @DouglasMcDonald It did output '0' and nothing else. I do not have it in a `{% cache %}` statement.
Comments.UserDisplayName: Nick
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-01-06T19:57:58.597Z
Comments.Text: FWIW, I just setup a test case locally with a table inside of Matrix and it's working as expected for me.  I'd try to narrow down your template to the most basic for possible and go from there.
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-01-06T20:14:52.233Z
Comments.Text: @DouglasMcDonald no luck so far, have made a gist https://gist.github.com/nickbytes/37e1bf3a5c03a047d36e and will try and pair things away (the naming is a little different, looking at last section of template)
Comments.UserDisplayName: Nick
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-01-06T20:15:24.397Z
Comments.Text: @BradBell made a gist, will try your advice and make most basic template to see what issue is https://gist.github.com/nickbytes/37e1bf3a5c03a047d36e
Comments.UserDisplayName: Nick
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-01-06T21:02:06.170Z
Comments.Text: @BradBell This seems to be simplest instance https://gist.github.com/nickbytes/8c2a1100b4828d92db98 just checking to see if that field shows each time. It is still showing everything in `<div class="accordion-section">`
Comments.UserDisplayName: Nick
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-01-06T21:02:21.330Z
Comments.Text: @DouglasMcDonald This seems to be simplest instance https://gist.github.com/nickbytes/8c2a1100b4828d92db98 just checking to see if that field shows each time. It is still showing everything in `<div class="accordion-section">`
Comments.UserDisplayName: Nick
Tags: <templating><matrix>
Title: How can I tell if a field exists in a block of a matrix?
ThreadText: # How can I tell if a field exists in a block of a matrix?
  
  (Asked by: username_0 on 2015-01-05)
  
  I want to see if a certain field exists in a block of a matrix. Here is my code.
  
  ```
  {% for block in entry.someStepContainer %}
    <div class="each-step">
  
      {% if block.type == "someStep" %}
        <div class="step-number"><span>{{loop.index}}</span></div>
        <h3 class="step-title">{{block.stepTitle}}</h3>
        <div class="step-description">{{block.stepDescription}}</div>
  
        <! -- this is part I'm trying to fix -->
  
        {% if block.stepAccordionContent %}
          <div class="accordion-section">
            {% for row in block.stepAccordionContent %}
              <h3 class="accordion-control">{{row.accordionTitle}}</h3>
              <p class="accordion-content" style="display: none;">{{row.accordionContent}}</p>
            {% endfor %}
          </div>
        {% endif %}
  
        <!-- end part -->
  
      {% endif %}
  
    </div>
  {% endfor %} 
  
  ```
  
  I've tried using:
  
  ```
  {% if block.stepAccordionContent | length %}
  
  ```
  
  But this still yields an empty
  
  ```
  <div class="accordion-section">
  
  ```
  
  `stepAccordionContent` is a table.
  
  **Tags:** templating, matrix
  
  > **Comments:**
  > **username_1**: You say your checking if a Matrix block exists, but it looks like you're checking if a field inside of a block has any data.  Can you clarify what `stepAccordionContent` is?  
  > **username_0**: @username_2 printing `{{block.stepAccordionContent|length}}` gives me `0`.  
  > **username_0**: @username_1 you're right. I have a matrix that is `someStepsContainer` with one block `someStep` and three fields, one of them being `stepAccordionContent` which is a table.  
  > **username_0**: @username_1 `stepAccordionContent` is a table  
  > **username_0**: @username_2 I was expecting if {%if block.stepAccordionContent|length%} returns 0, nothing inside the conditional would show. Instead, all content is showing (empty `h3` and `p`)  
  > **username_0**: @username_2 doesn't work there either. I'm wondering if it's just checking for the presence of that field, in which case, it's always there, though it may be empty (which it is not checking for)  
  > **username_0**: @username_2 are you asking if I've cleared my cache recently? (Sorry, not sure if "using `cache`" is something Craft-specific)  
  > **username_0**: @username_2 It did output '0' and nothing else. I do not have it in a `{% cache %}` statement.  
  > **username_1**: FWIW, I just setup a test case locally with a table inside of Matrix and it's working as expected for me.  I'd try to narrow down your template to the most basic for possible and go from there.  
  > **username_0**: @username_2 no luck so far, have made a gist https://gist.github.com/nickbytes/37e1bf3a5c03a047d36e and will try and pair things away (the naming is a little different, looking at last section of template)  
  > **username_0**: @username_1 made a gist, will try your advice and make most basic template to see what issue is https://gist.github.com/nickbytes/37e1bf3a5c03a047d36e  
  > **username_0**: @username_1 This seems to be simplest instance https://gist.github.com/nickbytes/8c2a1100b4828d92db98 just checking to see if that field shows each time. It is still showing everything in `<div class="accordion-section">`  
  > **username_0**: @username_2 This seems to be simplest instance https://gist.github.com/nickbytes/8c2a1100b4828d92db98 just checking to see if that field shows each time. It is still showing everything in `<div class="accordion-section">`  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2015-01-06. Score: 1 | Accepted answer
  
  You can use `{% if block.stepAccordionContent|length %}...{% endif %}` to test if any rows are defined in your table field.
  
  Note: When you create a table field it will have an empty row defined under 'Default Values', which should be removed; otherwise all new instances of the table will have an empty row defined by default causing `block.stepAccordionContent|length` to return 1, instead of 0 as expected.
  
  > **Comments:**
  > **username_1**: I'd also make sure you're looking at the correct `fellowshipStep` block since there could be multiple ones on the entry.  
  > **username_0**: My Test1: showed '1' for each, every 'foo' showed up, and in my entry with stepAccordionContent, Test1 showed '5' and the `accordion-selection` div, along with foo's  
  > **username_2**: I think I may have figured out your problem. In the table field settings in your matrix field, there is something called 'Default Values'. I would guess that you have one empty row defined, such that when you create a new matrix block, by default it has one empty row in it; thus when you run your test you get 1 for length, even though it looks empty. If you actually delete the empty row I would guess that it returns zero as expected. Go into your settings and delete that extra row from the 'Default Values', and the problem should go away.  
  > **username_0**: @username_2 I did have an empty row as a default value! Once I deleted this from the field settings, then went and deleted it for each entry already created, it worked!!!!! Bravo bravo!!!!  
  > **username_0**: You should add this as an answer!  
  > **username_2**: Great! whew. I updated the answer and deleted all my comments to help clean this up a bit.  
  
  ---
  
  