<p>If I'm understanding what you've asked correctly (and there's every chance I'm not – it's been a long day), I've got something similar on one of my sites and I'm using the following code:</p>

<pre><code>{% for faq in entry.faq if faq.column == 'Left' %}
    &lt;li&gt;
        &lt;h3&gt;{{ faq.question }}&lt;/h3&gt;
        &lt;p&gt;{{ faq.answer }}&lt;/p&gt;
    &lt;/li&gt;
{% endfor %}
</code></pre>

<p>then:</p>

<pre><code>{% for faq in entry.faq if faq.column == 'Right' %}
    &lt;li&gt;
        &lt;h3&gt;{{ faq.question }}&lt;/h3&gt;
        &lt;p&gt;{{ faq.answer }}&lt;/p&gt;
    &lt;/li&gt;
{% endfor %}
</code></pre>

<p>In this case 'faq' is the Matrix field and 'faq.column' is the Position Select field.</p>

<p>There are neater ways to do this to avoid the repeated code, but you get the idea.</p>

CC BY-SA 3.0
2014-11-06T20:08:57.933Z
That's actually a pretty elegant solution! Not to mention didn't know you could combine the for and if statements!
crawf
CC BY-SA 3.0
2014-11-06T18:36:41.230Z
2014-11-06T18:36:41.230Z
Steve Abraham
<p>Just working with a Matrix field to create a flexible, 2 column layout. The user can choose to add either an Image or Rich Text field, and position them accordingly with the Position Select field.</p>

<p>To illustrate, one layout might be:</p>

<pre><code>| image | image |
|       |       |
| text  | text  |
</code></pre>

<p>But another might be:</p>

<pre><code>| image | text  |
|       |       |
| image | text  |
</code></pre>

<p>Now my solution is to first loop through the Matrix field for each possible position option and group fields depending on their position into arrays. ie: <code>leftContent[]</code>, <code>rightContent[]</code>, etc.</p>

<p>Printing them out is then simple:</p>

<pre><code>&lt;div class="col col-6 mobile-full"&gt;
    {% for row in leftContent %}
        {% if row.type == 'image' %}
            &lt;img src="{{ row.image.first().getUrl() }}" /&gt;
        {% else %}
            {{ row.text }}
        {% endif %}
    {% endfor %}
&lt;/div&gt;
</code></pre>

<p>It would certainly make things easier if you could grab fields for x position? I'm aware this is more of a HTML layout issue and should really be left to the template creator to figure out, but just wanted to see if people had come across this.</p>

<p>Hope that makes sense :)</p>

CC BY-SA 3.0
2014-11-06T14:08:19.777Z
possible duplicate of [How can I return specific matrix rows based on criteria?](http://craftcms.stackexchange.com/questions/2307/how-can-i-return-specific-matrix-rows-based-on-criteria)
carlcs
CC BY-SA 3.0
2014-11-06T14:14:45.200Z
Hey crawf! I think it's not possible to grab only those matrix blocks with that criteria (→ see that other question). But you found a good workaround to separate them using two arrays `leftContent[]`, `rightContent[]`!
carlcs
CC BY-SA 3.0
2014-11-06T20:10:18.040Z
@carlcs I did see that question, and workaround is a little overboard, but works for the moment!
crawf
<templating><matrix><filter>
Get all fields within Matrix for position?
# Get all fields within Matrix for position?

(Asked by: username_0 on 2014-11-06)

Just working with a Matrix field to create a flexible, 2 column layout. The user can choose to add either an Image or Rich Text field, and position them accordingly with the Position Select field.
To illustrate, one layout might be:
| image | image |
|       |       |
| text  | text  |

But another might be:
| image | text  |
|       |       |
| image | text  |

Now my solution is to first loop through the Matrix field for each possible position option and group fields depending on their position into arrays. ie: leftContent[], rightContent[], etc.
Printing them out is then simple:

    {% for row in leftContent %}
        {% if row.type == 'image' %}
            
        {% else %}
            {{ row.text }}
        {% endif %}
    {% endfor %}


It would certainly make things easier if you could grab fields for x position? I'm aware this is more of a HTML layout issue and should really be left to the template creator to figure out, but just wanted to see if people had come across this.
Hope that makes sense :)

**Tags:** templating, matrix, filter
> **Comments:**
> **username_1**: possible duplicate of [How can I return specific matrix rows based on criteria?](http://craftcms.stackexchange.com/questions/2307/how-can-i-return-specific-matrix-rows-based-on-criteria)  
> **username_1**: Hey crawf! I think it's not possible to grab only those matrix blocks with that criteria (→ see that other question). But you found a good workaround to separate them using two arrays `leftContent[]`, `rightContent[]`!  
> **username_0**: @carlcs I did see that question, and workaround is a little overboard, but works for the moment!  

---

## 1 answers

### Answer by username_2 on 2014-11-06. Score: 2 | Accepted answer

If I'm understanding what you've asked correctly (and there's every chance I'm not – it's been a long day), I've got something similar on one of my sites and I'm using the following code:
{% for faq in entry.faq if faq.column == 'Left' %}
    
        {{ faq.question }}
        {{ faq.answer }}
    
{% endfor %}

then:
{% for faq in entry.faq if faq.column == 'Right' %}
    
        {{ faq.question }}
        {{ faq.answer }}
    
{% endfor %}

In this case 'faq' is the Matrix field and 'faq.column' is the Position Select field.
There are neater ways to do this to avoid the repeated code, but you get the idea.

> **Comments:**
> **username_0**: That's actually a pretty elegant solution! Not to mention didn't know you could combine the for and if statements!  

---

