<p>You can loop through all of the selected values of a multi-select field like this:</p>



<pre class="lang-html prettyprint-override"><code>{% for value in entry.myFieldHandle %}
  &lt;li&gt;{{ value }}&lt;/li&gt;
{% endfor %}
</code></pre>

<p>(See the <a href="http://buildwithcraft.com/docs/multi-select-fields#templating" rel="nofollow">Multi-select field docs</a> for other examples.)</p>

<p>The easiest way to loop through <em>all</em> of your multi-select fields’ values would be to manually merge all of their values into a new array:</p>

<pre class="lang-html prettyprint-override"><code>{% set values = entry.fieldHandleOne
    |merge([entry.fieldHandleTwo])
    |merge([entry.fieldHandleThree]) %}

{% for value in values %}
    {{ value }}
{% endfor %}
</code></pre>

<p>If you really don’t want to hardcode the field handles in your template, then you can go the getFieldLayout() route. That <code>field.getField()</code> function will give you the actual <a href="http://buildwithcraft.com/classreference/models/FieldModel" rel="nofollow">FieldModel</a> that represents the field. You can use its <code>handle</code> property to access the field’s selected values on your <code>entry</code>:</p>

<pre class="lang-html prettyprint-override"><code>{% set values = [] %}

{% for tab in entry.getFieldLayout().getTabs() %}
  {% if tab.name == 'Spec' %}
    {% for field in tab.getFields() %}
      {% set handle = field.getField().handle %}
      {% set fieldValues = entry.getFieldValue(handle) %}
      {% set values = values|merge([fieldValues]) %}
    {% endfor %}
  {% endif %}
{% endfor %}

{% for value in values %}
  {% for selected in value %}
    &lt;li&gt;{{ selected}}&lt;/li&gt;
  {% endfor %}
{% endfor %}
</code></pre>

CC BY-SA 3.0
2015-10-20T08:46:02.737Z
Hi, thank you for response. I have been trying your solution, but I get this error `The merge filter only works with arrays or hashes; array and object given.`.
Ivaylo Petrov
CC BY-SA 3.0
2015-10-20T08:58:57.003Z
I made a quick search and solve the problem adding square brackets `{% set values = values|merge([fieldValues]) %}` and another loop to print the values `{% for value in values %} {% for selected in value %}  <li>{{ selected }}</li>
{% endfor %} {% endfor %}`. If There is a better solution I will be glad to know it. Thanks for help.
Ivaylo Petrov
CC BY-SA 3.0
2015-10-20T20:12:11.583Z
@IvayloPetrov Whoops, sorry about that! Just fixed the code.
Brandon Kelly
CC BY-SA 3.0
2015-10-21T06:53:57.663Z
Don`t worry, we all are humans ;) You miss to fix last code example :) I fixed it :)
Ivaylo Petrov
CC BY-SA 3.0
2015-10-19T22:25:27.950Z
2015-10-21T13:32:15.303Z
2015-10-21T13:32:15.303Z
Brandon Kelly
<p>I am new in Craft, and will be happy if I can get help with this task. I have a tab that contains only multiselect fields. What I want to do, is to get all selected values for all multiselects field in this tab. I find this <a href="https://craftcms.stackexchange.com/a/5253/4109">answer</a> to get all field from a tab, but I can't get the selected values for the entry. Here is my code:</p>

<pre><code>{% for tab in entry.getFieldLayout().getTabs() %}
  {% if tab.name == 'Spec' %}
    &lt;ul&gt;
      &lt;li&gt;{{ tab.name }}
        &lt;ul&gt;
          {% for field in tab.getFields() %}
            &lt;li&gt;{{ field.getField().name }}&lt;/li&gt;
          {% endfor %}
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  {% endif %}
{% endfor %}
</code></pre>

<templating>
Get selected values from all of an entry’s Multi-select fields
# Get selected values from all of an entry’s Multi-select fields

(Asked by: username_0 on 2015-10-19)

I am new in Craft, and will be happy if I can get help with this task. I have a tab that contains only multiselect fields. What I want to do, is to get all selected values for all multiselects field in this tab. I find this answer to get all field from a tab, but I can't get the selected values for the entry. Here is my code:
{% for tab in entry.getFieldLayout().getTabs() %}
  {% if tab.name == 'Spec' %}
    
      {{ tab.name }}
        
          {% for field in tab.getFields() %}
            {{ field.getField().name }}
          {% endfor %}
        
      
    
  {% endif %}
{% endfor %}

**Tags:** templating


---

## 1 answers

### Answer by username_1 on 2015-10-19. Score: 2 | Accepted answer

You can loop through all of the selected values of a multi-select field like this:
{% for value in entry.myFieldHandle %}
  {{ value }}
{% endfor %}

(See the Multi-select field docs for other examples.)
The easiest way to loop through all of your multi-select fields’ values would be to manually merge all of their values into a new array:
{% set values = entry.fieldHandleOne
    |merge([entry.fieldHandleTwo])
    |merge([entry.fieldHandleThree]) %}

{% for value in values %}
    {{ value }}
{% endfor %}

If you really don’t want to hardcode the field handles in your template, then you can go the getFieldLayout() route. That field.getField() function will give you the actual FieldModel that represents the field. You can use its handle property to access the field’s selected values on your entry:
{% set values = [] %}

{% for tab in entry.getFieldLayout().getTabs() %}
  {% if tab.name == 'Spec' %}
    {% for field in tab.getFields() %}
      {% set handle = field.getField().handle %}
      {% set fieldValues = entry.getFieldValue(handle) %}
      {% set values = values|merge([fieldValues]) %}
    {% endfor %}
  {% endif %}
{% endfor %}

{% for value in values %}
  {% for selected in value %}
    {{ selected}}
  {% endfor %}
{% endfor %}

> **Comments:**
> **username_0**: Hi, thank you for response. I have been trying your solution, but I get this error `The merge filter only works with arrays or hashes; array and object given.`.  
> **username_0**: I made a quick search and solve the problem adding square brackets `{% set values = values|merge([fieldValues]) %}` and another loop to print the values `{% for value in values %} {% for selected in value %}  <li>{{ selected }}</li> {% endfor %} {% endfor %}`. If There is a better solution I will be glad to know it. Thanks for help.  
> **username_1**: @IvayloPetrov Whoops, sorry about that! Just fixed the code.  
> **username_0**: Don`t worry, we all are humans ;) You miss to fix last code example :) I fixed it :)  

---

