Answers.Body: <p>Live preview have gone through a major refactoring for Craft 3.2, which addresses this issue. For Craft 3.1 and below see solutions below.</p>
  
  <hr>
  
  <p>This is happening because Matrix will only show the non-live blocks so long as you don’t set any Matrix parameters in your template. As soon as you tell it to only show blocks of a certain type, it no longer feels confident that the blocks it was going to output are the right ones, so it will dump them and run a new DB query.</p>
  
  <p>One possible way around this would be to do this:</p>
  
  <p><em>Craft 2:</em></p>
  
  <pre><code>{% if craft.request.isLivePreview %}
      {% set firstCopyBlock = null %}
      {% for block in entry.matrixField %}
          {% if firstCopyBlock == null and block.type.handle == 'copy' %}
              {% set firstCopyBlock = block %}
          {% endif %}
      {% endfor %}
  {% else %}
      {% set firstCopyBlock = entry.matrixField.type('copy').first() %}
  {% endif %}
  
  {% if firstCopyBlock %}
      {{ firstCopyBlock.plainText }}
  {% endif %}
  </code></pre>
  
  <p><em>Craft 3:</em></p>
  
  <pre><code>{% if craft.app.request.isLivePreview %}
      {% set firstCopyBlock = null %}
      {% for block in entry.matrixField.all() %}
          {% if firstCopyBlock == null and block.type.handle == 'copy' %}
              {% set firstCopyBlock = block %}
          {% endif %}
      {% endfor %}
  {% else %}
      {% set firstCopyBlock = entry.matrixField.type('copy').one() %}
  {% endif %}
  
  {% if firstCopyBlock %}
      {{ firstCopyBlock.plainText }}
  {% endif %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2015-03-26T19:21:36.463Z
Answers.LastActivityDate: 2019-05-18T12:31:19.890Z
Answers.LastEditDate: 2019-05-18T12:31:19.890Z
Answers.UserDisplayName: Brandon Kelly
Body: <p>I have problems getting Live Preview to work with this Twig code that gets data from a Matrix field.</p>
  
  <pre><code>{{ entry.matrixField.type('copy').nth(0).plainText }}
  </code></pre>
  
  <p>As soon as I remove the <code>type</code> property from the criteria model, it does update on entry changes again!</p>
  
Tags: <matrix><live-preview>
Title: Issue with Matrix `type` property and Live Preview?
ThreadText: # Issue with Matrix `type` property and Live Preview?
  
  (Asked by: username_0 on 2015-03-26)
  
  I have problems getting Live Preview to work with this Twig code that gets data from a Matrix field.
  
  ```
  {{ entry.matrixField.type('copy').nth(0).plainText }}
  
  ```
  
  As soon as I remove the `type` property from the criteria model, it does update on entry changes again!
  
  **Tags:** matrix, live-preview
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-03-26. Score: 5 | Accepted answer
  
  Live preview have gone through a major refactoring for Craft 3.2, which addresses this issue. For Craft 3.1 and below see solutions below.
  
  ---
  
  This is happening because Matrix will only show the non-live blocks so long as you don’t set any Matrix parameters in your template. As soon as you tell it to only show blocks of a certain type, it no longer feels confident that the blocks it was going to output are the right ones, so it will dump them and run a new DB query.
  
  One possible way around this would be to do this:
  
  *Craft 2:*
  
  ```
  {% if craft.request.isLivePreview %}
      {% set firstCopyBlock = null %}
      {% for block in entry.matrixField %}
          {% if firstCopyBlock == null and block.type.handle == 'copy' %}
              {% set firstCopyBlock = block %}
          {% endif %}
      {% endfor %}
  {% else %}
      {% set firstCopyBlock = entry.matrixField.type('copy').first() %}
  {% endif %}
  
  {% if firstCopyBlock %}
      {{ firstCopyBlock.plainText }}
  {% endif %}
  
  ```
  
  *Craft 3:*
  
  ```
  {% if craft.app.request.isLivePreview %}
      {% set firstCopyBlock = null %}
      {% for block in entry.matrixField.all() %}
          {% if firstCopyBlock == null and block.type.handle == 'copy' %}
              {% set firstCopyBlock = block %}
          {% endif %}
      {% endfor %}
  {% else %}
      {% set firstCopyBlock = entry.matrixField.type('copy').one() %}
  {% endif %}
  
  {% if firstCopyBlock %}
      {{ firstCopyBlock.plainText }}
  {% endif %}
  
  ```
  
  
  ---
  
  