Adding Random Class from Field

It would be easier if Kirby supported query language for the default option out of the box, but that isn’t the case.

So to make this you have two options:

  1. The easy way: Use a page.create:after hook and update the page within the hook. You can either hard-code your array of options into the hook code, or you read the options from the blueprint (see Using blueprints in the frontend | Kirby CMS). Maybe I should add that you cannot use the shuffle() method on an array, but have to resort to A::shuffle.

  2. Or you create a custom color field and overwrite the default method, like in the examples here: Dynamic default number field - #2 by texnixe. Not much more difficult and you only need to do this once and can reuse it in other parts if needed without having to adapt any hooks.