Pluralise label depending on value?

I’m trying to change a label text between singular and plural depending on how many items there are in the ‘structure’.

I’ve tried so far to look at Ternary operator but it’s beyond my experience.
Here is what I have tried so far:

label: "{{ page.clients.toStructure.count.not(1) ? 'client' : 'clients' }}"

and the full structure code:

fields:
      clients:
        label: "{{ page.clients.toStructure.count.not(1) ? 'client' : 'clients' }}"
        type: structure
        fields:
          clientname:
            label: name
            type: text
          clienturl:
            label: website
            type: url
          clientinstagramhandle:
            label: instagram
            type: text
      categories:
        type: structure
        fields:
          category:
            label: Project categories
            type: text

Any suggestions or hints would be greatly appreciated.

Kirby: 4.1.0
PHP: 8.3.3
Browser: Safari 17.3
OS: Mac 14.3

This cannot possibly work, because you cannot call a collection method (not()) on an integer (the return type of count()).

You would need a custom page method here that returns a boolean.

label: "{{ page.isOneClient() ? 'client' : 'clients' }}"

Although I would expect clients when I am supposed to add multiple entries, and client if I am supposed to enter a single client, and not a label that depends on the number of actually entered entries?

thanks for the input :slight_smile:
I got it working with a custom page model for another label I need to change depending on the quantity of entries.

foreach ($tagCount as $tag => $count) {
            $label = $tag . ($count > 1 ? ' projects' : ' project');
            $resultArray[] = [
                'label' => $label,
                'value' => $count,
            ];
        }

It’s mostly a cosmetic thing but I prefer when it’s plural when regering to more and singular when only one.

Here is how it looks on my generated labels on the stats depending on quantity: