<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>

CC BY-SA 3.0
2016-01-25T18:43:08.843Z
I had to enclose the field handle in quotes otherwise I got a "variable does not exist" erorr `{{ contentBlock.prev['matrixField'] }}`
Gogster
CC BY-SA 3.0
2015-07-25T20:30:18.403Z
2015-07-25T20:30:18.403Z
Steve Adams
<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>

<matrix>
How to access a previous matrix field value
# 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'] }}`  

---

