<p>I'm referencing the Pixel &amp; Tonic sample craft template Happy Lager where in the article body template there's a macro to get the position of a block.</p>

<p>I'm trying to setup a conditional to check if the previous position of a block has been set to 'left'.</p>

<pre><code>{% if prevPosition == 'left' %}
</code></pre>

<p>But that doesn't seem to work at all.</p>

<p><a href="https://github.com/pixelandtonic/HappyLager/blob/master/craft/templates/_includes/article_body.html" rel="nofollow">https://github.com/pixelandtonic/HappyLager/blob/master/craft/templates/_includes/article_body.html</a></p>

CC BY-SA 3.0
2016-01-18T21:22:38.830Z
What is `prevPosition`? `{{dump(prevPosition)}}` to display it...
Marion Newlevant
CC BY-SA 3.0
2016-01-18T21:26:45.990Z
It's NULL even though the previous block has position left.
Niall Thompson
CC BY-SA 3.0
2016-01-18T21:35:01.190Z
Just looking at that macro, `prevPosition` should be set properly in lines 32-184. You need to be sure it is defined outside of the for loop (line 20), or else you will get a new, `null` one every time.
Marion Newlevant
CC BY-SA 3.0
2016-01-21T22:26:32.300Z
Where are you trying to insert this conditional? Inside the macro?
André Elvan
CC BY-SA 3.0
2016-01-21T22:27:42.820Z
No outside in the article body template
Niall Thompson
<conditional><macro>
Conditional to check position of previous matrix block
# Conditional to check position of previous matrix block

(Asked by: username_0 on 2016-01-18)

I'm referencing the Pixel & Tonic sample craft template Happy Lager where in the article body template there's a macro to get the position of a block.
I'm trying to setup a conditional to check if the previous position of a block has been set to 'left'.
{% if prevPosition == 'left' %}

But that doesn't seem to work at all.
https://github.com/pixelandtonic/HappyLager/blob/master/craft/templates/_includes/article_body.html

**Tags:** conditional, macro

> **Comments:**
> **username_1**: What is `prevPosition`? `{{dump(prevPosition)}}` to display it...  
> **username_0**: It's NULL even though the previous block has position left.  
> **username_1**: Just looking at that macro, `prevPosition` should be set properly in lines 32-184. You need to be sure it is defined outside of the for loop (line 20), or else you will get a new, `null` one every time.  
> **username_2**: Where are you trying to insert this conditional? Inside the macro?  
> **username_0**: No outside in the article body template  

---

## 0 answers

