<p>You get all available options with the <code>options</code> attribute and you can check if it is selected in the current entry with <code>option.selected</code></p>

<pre><code>{% for opt in entry.checkboxFieldHandle.options %}
    &lt;label&gt;
        &lt;input name="fields[checkboxFieldHandle][]" type="checkbox" value="{{ opt.value }}"&gt;
        {{ opt.label }}
        {% if opt.selected %}
            I'm selected
        {% endif %}
    &lt;/label&gt;
{% endfor %}
</code></pre>

<p>But to be honest I don't really understand your second part</p>

<p><strong>Edit</strong><br>
As for your field, you can display all the selected values with</p>

<pre><code>{% set selectedUserGroupIds = entry.userGroupFieldHandle %}
{% for userGroupId in selectedUserGroupIds %}
    {% set usergroup = craft.userGroups.getGroupById(userGroupId) %}
    {{ usergroup.name }}
{% endfor %}
</code></pre>

CC BY-SA 3.0
2017-12-20T20:55:30.043Z
Maybe it's the field I'm using but that standard methodology is not working. I am using this plugin:
https://github.com/quebecstudio/usergroupfield

It creates a new field called usergroups and when added to a "section" it shows all the user groups in the system with empty checkboxes beside each. Hoping to use this to create very flexible page permissions (i.e. edit entry 1 and assign user group A,B, and F, then only users in groups A,B or F can access this page).
Max
CC BY-SA 3.0
2017-12-20T21:00:17.183Z
Yes you can do this with the plugin. But you don't need to display the selected values in your frontend to achieve that.
Robin Schambach
CC BY-SA 3.0
2017-12-20T22:06:06.317Z
Hi Robin, was trying to display the values selected as a visual check to make sure it was grabbing the right data.

There's not a ton of documentation around that plugin so I'm not sure exactly how to get it working as desired.
Max
CC BY-SA 3.0
2017-12-21T08:37:08.407Z
Well, I'm not really sure what you want... `entry.userGroupFieldHandle` contains an array with all selected usergroup ids and an empty string if nothing was selected. You can check if it is not empty, loop through the results and get the selected group by id
Robin Schambach
CC BY-SA 3.0
2017-12-21T20:14:18.367Z
I did get the id's to display, but not sure how to translate that into giving permissions. Thanks for your help.
Max
CC BY-SA 3.0
2017-12-21T21:16:24.827Z
You should start to explain what you want properly. You said you want to display the selected values in your field. So all user groups now you say you want to create a form to change user permissions.
Robin Schambach
CC BY-SA 3.0
2017-12-20T20:28:05.697Z
2017-12-21T08:54:24.827Z
2017-12-21T08:54:24.827Z
Robin Schambach
<p>If you have a <code>checkbox</code>  field on an entry type, how do you display all the selected values for an entry in a template with twig?</p>

<p>Using this for page permissions via user groups. We have a plugin that adds a new field type "user groups". It lists all groups (which we have many) on the admin page of each entry. We want to check which groups will have access and then limit the page to users in that group only.</p>

<p>edit: not using a standard checkbox field but a new field (via plugin). <a href="https://github.com/quebecstudio/usergroupfield" rel="nofollow noreferrer">https://github.com/quebecstudio/usergroupfield</a></p>

<templating><permissions>
Output Checkbox Data on Template
# Output Checkbox Data on Template

(Asked by: username_0 on 2017-12-20)

If you have a `checkbox` field on an entry type, how do you display all the selected values for an entry in a template with twig?

Using this for page permissions via user groups. We have a plugin that adds a new field type "user groups". It lists all groups (which we have many) on the admin page of each entry. We want to check which groups will have access and then limit the page to users in that group only.

edit: not using a standard checkbox field but a new field (via plugin). <https://github.com/quebecstudio/usergroupfield>

**Tags:** templating, permissions

---

## 1 answers

### Answer by username_1 on 2017-12-20. Score: 1

You get all available options with the options attribute and you can check if it is selected in the current entry with option.selected
{% for opt in entry.checkboxFieldHandle.options %}
    
        
        {{ opt.label }}
        {% if opt.selected %}
            I'm selected
        {% endif %}
    
{% endfor %}

But to be honest I don't really understand your second part
Edit
As for your field, you can display all the selected values with
{% set selectedUserGroupIds = entry.userGroupFieldHandle %}
{% for userGroupId in selectedUserGroupIds %}
    {% set usergroup = craft.userGroups.getGroupById(userGroupId) %}
    {{ usergroup.name }}
{% endfor %}

> **Comments:**
> **username_0**: Maybe it's the field I'm using but that standard methodology is not working. I am using this plugin: https://github.com/quebecstudio/usergroupfield  It creates a new field called usergroups and when added to a "section" it shows all the user groups in the system with empty checkboxes beside each. Hoping to use this to create very flexible page permissions (i.e. edit entry 1 and assign user group A,B, and F, then only users in groups A,B or F can access this page).  
> **username_1**: Yes you can do this with the plugin. But you don't need to display the selected values in your frontend to achieve that.  
> **username_0**: Hi Robin, was trying to display the values selected as a visual check to make sure it was grabbing the right data.  There's not a ton of documentation around that plugin so I'm not sure exactly how to get it working as desired.  
> **username_1**: Well, I'm not really sure what you want... `entry.userGroupFieldHandle` contains an array with all selected usergroup ids and an empty string if nothing was selected. You can check if it is not empty, loop through the results and get the selected group by id  
> **username_0**: I did get the id's to display, but not sure how to translate that into giving permissions. Thanks for your help.  
> **username_1**: You should start to explain what you want properly. You said you want to display the selected values in your field. So all user groups now you say you want to create a form to change user permissions.  

---

