<p>You'd use the checkbox fields much the same way they would be used if they were added directly to the entry and not in the matrix field. Assuming you've got a basic matrix field structure (using <a href="https://docs.craftcms.com/v3/matrix-fields.html#templating" rel="nofollow noreferrer"><code>if</code>/<code>else</code></a> or <a href="https://docs.craftcms.com/v3/dev/tags/switch.html" rel="nofollow noreferrer"><code>switch</code></a>):</p>

<pre><code>{% for block in entry.myMatrixField.all() %}

    {% switch block.type %}

        {% case "text" %}

            {{ block.textField | markdown }}

        {% case "image" %}

            {{ block.image[0].getImg() }}

        {% case "checkboxes" %}

            // HELP!!!

        {% default %}

            &lt;p&gt;A font walks into a bar.&lt;/p&gt;
            &lt;p&gt;The bartender says, “Hey, we don’t serve your type in here!”&lt;/p&gt;

    {% endswitch %}

{% endfor %}
</code></pre>

<p>You could use the same examples that are in the <a href="https://docs.craftcms.com/v3/checkboxes-fields.html#templating-examples" rel="nofollow noreferrer">docs</a> and just switch <code>entry</code> for the name of your block variable (<code>block</code> in our case):</p>

<h3>Loop through the checked checkboxes:</h3>

<pre><code>{% for option in block.checkboxFieldHandle %}
    Label: {{ option.label }}
    Value: {{ option }} or {{ option.value }}
{% endfor %}
</code></pre>

<h3>Loop through all of the available checkboxes:</h3>

<pre><code>{% for option in block.checkboxFieldHandle.options %}
    Label:   {{ option.label }}
    Value:   {{ option }} or {{ option.value }}
    Checked: {{ option.selected ? 'Yes' : 'No' }}
{% endfor %}
</code></pre>

<h3>See if any checkboxes are checked:</h3>

<pre><code>{% if block.checkboxFieldHandle|length %}
</code></pre>

<h3>See if a particular checkbox is checked:</h3>

<pre><code>{% if block.checkboxFieldHandle.contains('optionValue') %}
</code></pre>

CC BY-SA 4.0
2018-12-28T12:42:14.643Z
2018-12-28T12:42:14.643Z
Jalen Davenport
<p>Newbie here.</p>

<p>First Craft 3 CMS build and fumbling with logic of Matrix blocks.</p>

<p>I've created a relatively simple matrix field, and I can output plain text and dropdown options, but not sure how to do a multiple choice field like checkboxes within a matrix.</p>

<p>Thanks</p>

<craft3><matrix><checkboxes>
How to output 'selected' checkbox labels within a matrix
# How to output 'selected' checkbox labels within a matrix

(Asked by: username_0 on 2018-12-28)

Newbie here.

First Craft 3 CMS build and fumbling with logic of Matrix blocks.

I've created a relatively simple matrix field, and I can output plain text and dropdown options, but not sure how to do a multiple choice field like checkboxes within a matrix.

Thanks

**Tags:** craft3, matrix, checkboxes

---

## 1 answers

### Answer by username_1 on 2018-12-28. Score: 1

You'd use the checkbox fields much the same way they would be used if they were added directly to the entry and not in the matrix field. Assuming you've got a basic matrix field structure (using if/else or switch):
{% for block in entry.myMatrixField.all() %}

    {% switch block.type %}

        {% case "text" %}

            {{ block.textField | markdown }}

        {% case "image" %}

            {{ block.image[0].getImg() }}

        {% case "checkboxes" %}

            // HELP!!!

        {% default %}

            A font walks into a bar.
            The bartender says, “Hey, we don’t serve your type in here!”

    {% endswitch %}

{% endfor %}

You could use the same examples that are in the docs and just switch entry for the name of your block variable (block in our case):
Loop through the checked checkboxes:
{% for option in block.checkboxFieldHandle %}
    Label: {{ option.label }}
    Value: {{ option }} or {{ option.value }}
{% endfor %}

Loop through all of the available checkboxes:
{% for option in block.checkboxFieldHandle.options %}
    Label:   {{ option.label }}
    Value:   {{ option }} or {{ option.value }}
    Checked: {{ option.selected ? 'Yes' : 'No' }}
{% endfor %}

See if any checkboxes are checked:
{% if block.checkboxFieldHandle|length %}

See if a particular checkbox is checked:
{% if block.checkboxFieldHandle.contains('optionValue') %}


---

