Answers.Body: <p>You could first set a variable to test against and then change it the first time the block type appears.</p>
  
  <pre><code>{% set firstTime = true %}
  
  {% for block in entry.matrixField %}
  
      {% if block.type == "text" and firstTime == true %}
  
          ...Do something once...
  
          {% set firstTime = false %}
  
      {% endif %}
  
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-19T03:16:09.050Z
Answers.LastActivityDate: 2015-04-19T03:16:09.050Z
Answers.UserDisplayName: Dylan T
Body: <p>I want to include a conditional for when the 'Text' block type is returned for the first time in a loop. In css it would be first-of-type.</p>
  
  <p>Here's what I have at the moment:</p>
  
  <pre><code>{% if type == 'text' and loop.first %}
      &lt;div class="centered spacer-icon m-all t-all d-all"&gt;&lt;img src="resources/img/minus-icon.svg" alt="Minus Icon" width="30" /&gt;&lt;/div&gt;
  {% endif %}
  </code></pre>
  
  <p>In this instance my text block type is loop index 3 but I want to adjust the conditional because it is the first text type in the matrix field.</p>
  
Tags: <matrix><conditional><loop>
Title: How Can I Include a Conditional for First Type of Matrix
ThreadText: # How Can I Include a Conditional for First Type of Matrix
  
  (Asked by: username_0 on 2015-04-19)
  
  I want to include a conditional for when the 'Text' block type is returned for the first time in a loop. In css it would be first-of-type.
  
  Here's what I have at the moment:
  
  ```
  {% if type == 'text' and loop.first %}
      <div class="centered spacer-icon m-all t-all d-all"><img src="resources/img/minus-icon.svg" alt="Minus Icon" width="30" /></div>
  {% endif %}
  
  ```
  
  In this instance my text block type is loop index 3 but I want to adjust the conditional because it is the first text type in the matrix field.
  
  **Tags:** matrix, conditional, loop
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-04-19. Score: 15 | Accepted answer
  
  You could first set a variable to test against and then change it the first time the block type appears.
  
  ```
  {% set firstTime = true %}
  
  {% for block in entry.matrixField %}
  
      {% if block.type == "text" and firstTime == true %}
  
          ...Do something once...
  
          {% set firstTime = false %}
  
      {% endif %}
  
  {% endfor %}
  
  ```
  
  
  ---
  
  