Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

@Blueprints > taxonomy field > default

Started by Muut Archive 10 years ago · 3 replies · 702 views
10 years ago

Hello all,

anyone knows, how I can set default values for the taxonomy field. Also changing the label text, would be nice.

Apart from that. What is the difference / advantage over using a normal selectize field for adding categories/tags?

10 years ago

Okay, for the last part of my question. It is more a select (list) field showing all your already applied categories and tags to choose from. Now I get it.

10 years ago

Taxonomy extends the standard select field. You can see the extra logic here:

TWIG
{% set taxonomies = (taxonomies is null ? admin.data('config/site').taxonomies : taxonomies) %}
{% set parentname = field.name %}

{% for name in taxonomies %}

    {% set value = array(data.value('header.taxonomy.' ~ name)|default([])) %}
    {% set sub_taxonomies = attribute(grav.taxonomy.taxonomy, name)|default([])|keys %}
    {% set list = []|merge(sub_taxonomies)|merge(value)|array_unique %}

    {% set field = {
        type: 'select',
        classes: 'fancy create',
        label: name|capitalize,
        name: parentname ~ '.' ~ name,
        multiple: true,
        options: list,
        style: field.style, 
        selectize: {
            create: true
        }
    } %}

    {% include ['forms/fields/select/select.html.twig'] %}
{% endfor %}

You can't really set defaults from the field, because the taxonomy is coming directly from the configured taxonomy as defined in the system.yaml.

9 years ago

Is there somewhere else a default taxonomy value can be set for certain blueprints or children in a collection?

I see here in the Blueprints Documentation that taxonomy appears to accept a default value, but I'm not quite sure how to appropriately set it. For example, if using a taxonomy of "categories", and I wanted to set that to "foo" in a specific blueprint, how could I do that?

It seems like otherwise the only option is to use a custom header field that can be defaulted, though I'm not sure if taxonomies are inherently more efficient than than using that method.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1346 9 years ago
Archive · by Muut Archive, 9 years ago
2 933 9 years ago
Archive · by Muut Archive, 9 years ago
2 4060 9 years ago
Archive · by Muut Archive, 9 years ago
1 2945 9 years ago
Archive · by Muut Archive, 9 years ago
3 1117 9 years ago