Options via structure field

Is it possible to define the options of a select field via the values from a structure field? I want to manage brands as a structure in the site options and want to have a dropdown of those brands in another template.

Again, this is not possible by default. But you can, of course, query the options in a custom field. Or use the JSON query API: https://getkirby.com/docs/cheatsheet/panel-fields/select (see dynamic options via JSON API)

1 Like

Good point. I tried to go the JSON route, but can’t get it to work in a different place, but still the same problem:

This is how I create the JSON:

c::set('routes', [
    'pattern' => 'api/users.json',
    'action' => function() {
      if(!site()->user()) go('/');

      $users = [];
      foreach (site()->users() as $user) {
        $users[$user->username()] = $user->firstName() . " " . $user->lastName();

      return response::json($users);

And in the blueprint I got:

    label: Testmonial Author
    type: select
    options: /api/users.json

However the dropdown remains empty, and it looks like there’s no additional request in the network inspector.

Problem with the JSON API is, you have to use an absolute URL, which means, you have to change your URL on localhost and remote, or use a remote URL right from the beginning.

An alternative would be to use the ControlledList plugin: https://github.com/rasteiner/controlledlist


bummer! :scream: well, this is unfortunate… I think this should really be possible. Still: even if I use an absolute url, it does not seem to work.

Just tried that out, and it works like charm! That’ll come in handy, thanks!

Had to try the controlledlist plugin for myself just now. Simple and effective :+1:

That’s strange, it should work. Have you made sure to use the correct URL like: