Answers.Body: <p>As it turns out, you must use bracketed and not dotted syntax for matrix fields.</p>
  
  <pre><code>{% for contentBlock in entry.contentBlocks %}
      {% if contentBlock.prev %}
          {% if contentBlock.prev[matrixField] is defined %}
              {{ contentBlock.prev[matrixField] }}
          {% endif %}
      {% endif 
      ....
  {% endfor %}
  </code></pre>
  
  <p>fixed this issue for me :)</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-25T18:43:08.843Z
Answers.Text: I had to enclose the field handle in quotes otherwise I got a "variable does not exist" erorr `{{ contentBlock.prev['matrixField'] }}`
Answers.UserDisplayName: Gogster
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-07-25T20:30:18.403Z
Answers.LastActivityDate: 2015-07-25T20:30:18.403Z
Answers.UserDisplayName: Steve Adams
Body: <p>I have a case where I need to access a previous matrix field's value (if it exists) in the next matrix loop result.</p>
  
  <pre><code>{% for contentBlock in entry.contentBlocks %}
      {% if contentBlock.prev %}
          {% if contentBlock.getPrev().matrixField | length %}
              {{ contentBlock.getPrev().matrixField }}
          {% endif %}
      {% endif 
      ....
  {% endfor %}
  </code></pre>
  
  <p>I know that my issue is with <code>{{ contentBlock.getPrev().matrixField }}</code> but I am not sure how to access the field value after trying several methods.  I'm sure it's something simple.</p>
  
  <p>Thanks :)</p>
  
Tags: <matrix>
Title: How to access a previous matrix field value
ThreadText: # How to access a previous matrix field value
  
  (Asked by: username_0 on 2015-07-25)
  
  I have a case where I need to access a previous matrix field's value (if it exists) in the next matrix loop result.
  
  ```
  {% for contentBlock in entry.contentBlocks %}
      {% if contentBlock.prev %}
          {% if contentBlock.getPrev().matrixField | length %}
              {{ contentBlock.getPrev().matrixField }}
          {% endif %}
      {% endif 
      ....
  {% endfor %}
  
  ```
  
  I know that my issue is with `{{ contentBlock.getPrev().matrixField }}` but I am not sure how to access the field value after trying several methods. I'm sure it's something simple.
  
  Thanks :)
  
  **Tags:** matrix
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2015-07-25. Score: 3 | Accepted answer
  
  As it turns out, you must use bracketed and not dotted syntax for matrix fields.
  
  ```
  {% for contentBlock in entry.contentBlocks %}
      {% if contentBlock.prev %}
          {% if contentBlock.prev[matrixField] is defined %}
              {{ contentBlock.prev[matrixField] }}
          {% endif %}
      {% endif 
      ....
  {% endfor %}
  
  ```
  
  fixed this issue for me :)
  
  > **Comments:**
  > **username_1**: I had to enclose the field handle in quotes otherwise I got a "variable does not exist" erorr `{{ contentBlock.prev['matrixField'] }}`  
  
  ---
  
  