Blueprints: how to filter roles for creating radio-options

Hi there,

I’m trying to create a list of radio-buttons with my custom roles in a blueprint and I’m stuck with querying the roles.

When in a page-template I do

var_dump($kirby->roles();

then I get an array with the existing roles.

But trying using the same object this way, doesn’t get me nowhere:

    type: group
    fields:
      access:
        label: Zugriffsrechte
        type: radio
        options: query
          query: 
            fetch: kirby.roles
            text: " {{ role.title }}"
            value: "{{ role.title }}"

Tried it with query: kirby.roles with and without the fetch- and the text/value-param, doesn’t make no difference.

What is the correct syntax?
And is there a way to omit the admin-role?

Thank you in advance and happy Easter!
Ralf

Hi @raschid You’ll have to replace role with item to make it work. That’s how I’m using the query on one of my sites.

type: group
fields:
  access:
    label: Zugriffsrechte
    type: radio
    options: query
    query: 
      fetch: kirby.roles
      text: " {{ item.name }}"
      value: "{{ item.name }}"

thank you @flokuek !!
that did it :smile:

And adding not(‘admin’) to the query restricts the available roles to those with less permissions. Great!

options: query
query:
  fetch: kirby.roles.not('admin')
  text: "{{item.name}}"
  value: "{{item.name}}"

Where did you find the item-option? It’s not in the article about the query-language

The only thing that resembles your solution is the arrayItem described here.

1 Like

I think at the time I searched through the source code and found it :slight_smile:

mhm, yes, ok …
I think I take it as it is and try to find the relevant source code somewhen else …
Thanks again :+1: