Answers.Body: <p>Your condition <code>{% if entry.contentMatrix.first %}</code> will check if there exists a block in your field or not, it does not check if your current block is the first or not. Since there is one the condition will always become true. What you want to do is to check if you are in the first loop or not so I would suggest you to do something like this</p>
  
  <pre><code>{% for key, block in entry.contentMatrix %}
      {% if key == 0 %}
  </code></pre>
  
  <p>Or something like that </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-20T11:52:30.987Z
Answers.Text: I'm getting the following error "Unexpected token "operator" of value "=" ("end of statement block" expected)."
Answers.UserDisplayName: JMKelley
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-20T12:06:11.393Z
Answers.Text: Sry I forgot an `=` it was a syntax error
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-19T21:30:22.687Z
Answers.LastActivityDate: 2018-01-20T12:05:27.970Z
Answers.LastEditDate: 2018-01-20T12:05:27.970Z
Answers.UserDisplayName: Robin Schambach
Body: <p>I'm trying to target the first matrix block and changing the structure of the HTML, but nesting an IF statement within the loop but it's actually not doing anything, instead it's just displaying both the same. </p>
  
  <pre><code>&lt;div id="accordion" role="tablist" class="accordion-vt"&gt;
  {% for block in entry.contentMatrix %}
  {% if entry.contentMatrix.first %}
  
    &lt;div class="card"&gt;
      &lt;div class="card-header" role="tab" id="headingOne"&gt;
        &lt;h1 class="mb-0"&gt;
          &lt;a data-toggle="collapse" href="#collapseOne" role="button" aria-expanded="true" aria-controls="collapseOne"&gt;
            {{ block.contentTitle }}
          &lt;/a&gt;
        &lt;/h1&gt;
      &lt;/div&gt;
  
      &lt;div id="collapseOne" class="collapse show" role="tabpanel" aria-labelledby="headingOne" data-parent="#accordion"&gt;
        &lt;div class="card-body"&gt;
          {{ block.contentDescription }}
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  
    {% else %}
  
    &lt;div class="card"&gt;
      &lt;div class="card-header" role="tab" id="headingOne"&gt;
        &lt;h1 class="mb-0"&gt;
          &lt;a data-toggle="collapse" href="#collapseOne" role="button" aria-expanded="true" aria-controls="collapseOne"&gt;
            {{ block.contentTitle }}
          &lt;/a&gt;
        &lt;/h1&gt;
      &lt;/div&gt;
  
      &lt;div id="collapseOne" class="collapse" role="tabpanel" aria-labelledby="headingOne" data-parent="#accordion"&gt;
        &lt;div class="card-body"&gt;
          {{ block.contentDescription }}
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  {% endfor %}
  &lt;/div&gt;
  </code></pre>
  
Tags: <templating><entry><forloop>
Title: Changing first matrix block
ThreadText: # Changing first matrix block
  
  (Asked by: username_0 on 2018-01-19)
  
  I'm trying to target the first matrix block and changing the structure of the HTML, but nesting an IF statement within the loop but it's actually not doing anything, instead it's just displaying both the same.
  
  ```
  <div id="accordion" role="tablist" class="accordion-vt">
  {% for block in entry.contentMatrix %}
  {% if entry.contentMatrix.first %}
  
    <div class="card">
      <div class="card-header" role="tab" id="headingOne">
        <h1 class="mb-0">
          <a data-toggle="collapse" href="#collapseOne" role="button" aria-expanded="true" aria-controls="collapseOne">
            {{ block.contentTitle }}
          </a>
        </h1>
      </div>
  
      <div id="collapseOne" class="collapse show" role="tabpanel" aria-labelledby="headingOne" data-parent="#accordion">
        <div class="card-body">
          {{ block.contentDescription }}
        </div>
      </div>
    </div>
  
    {% else %}
  
    <div class="card">
      <div class="card-header" role="tab" id="headingOne">
        <h1 class="mb-0">
          <a data-toggle="collapse" href="#collapseOne" role="button" aria-expanded="true" aria-controls="collapseOne">
            {{ block.contentTitle }}
          </a>
        </h1>
      </div>
  
      <div id="collapseOne" class="collapse" role="tabpanel" aria-labelledby="headingOne" data-parent="#accordion">
        <div class="card-body">
          {{ block.contentDescription }}
        </div>
      </div>
    </div>
  {% endfor %}
  </div>
  
  ```
  
  **Tags:** templating, entry, forloop
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-01-19. Score: 2 | Accepted answer
  
  Your condition `{% if entry.contentMatrix.first %}` will check if there exists a block in your field or not, it does not check if your current block is the first or not. Since there is one the condition will always become true. What you want to do is to check if you are in the first loop or not so I would suggest you to do something like this
  
  ```
  {% for key, block in entry.contentMatrix %}
      {% if key == 0 %}
  
  ```
  
  Or something like that
  
  > **Comments:**
  > **username_0**: I'm getting the following error "Unexpected token "operator" of value "=" ("end of statement block" expected)."  
  > **username_1**: Sry I forgot an `=` it was a syntax error  
  
  ---
  
  