Category Groups fields have a Single Selection setting, which controls the behaviour of the field. This setting is disabled by default. When this setting is disabled, the field will resemble a typical multi-select field on an element edit page, and accessing the field in your templates will give you an array of the selected category groups. When Single Selection is enabled, the field will resemble a dropdown field on an element edit page, and accessing the field in your templates will give you the category group model.

Field data is not altered immediately on changing this setting, in case the setting was changed by accident; the data will only be overwritten when actually resaving its element. However, when Single Selection is enabled, the element edit page and templates will treat the first (in alphabetical order) selected category group as the field's only category group.

Template example: Single Selection disabled

{% if entry.categoryGroupsField %}
    <p>Multi-selection category groups field:</p>
        {% for group in entry.categoryGroupsField %}
            <p>{{ group.name }}</p>
        {% endfor %}
    </p>
{% else %}
    <p>No category groups selected :(</p>
{% endif %}

Template example: Single Selection enabled

{% if entry.categoryGroupField %}
    <p>Single selection category group field: {{ entry.categoryGroupField.name }}</p>
{% else %}
    <p>No category group selected :(</p>
{% endif %}
Installation Instructions

To install this plugin, copy the command above to your terminal.

Active Installs
124
Version
1.3.0
License
MIT
Compatibility
Craft 3, Craft 4
Last release
December 23, 2021
Categories
Activity (30 days)
0
Closed Issues
0
Open Issues
0
Merged PRs
0
Open PRs