Category Groups Field


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 %}

Free

Package Name

To install this plugin, search for its package name on the Plugin Store and click “Install”.


Information

  • Version 1.0.2
  • Last Update 9/17/2019
  • Active Installs 5
  • Compatibility Craft 3
  • License MIT
  • Categories Fields

Report an issue