Dynamic default number field

Hi,
In my siteMethods, I get a number that I’d like to use as a default for a field in my blueprint.

‘getSeason’ => function () {
… (some calculs)
$age = date(‘Y’) - $then_year;
return (int)$age;
},

And my blueprint is as simple as this :

season:
  type: number
  default: "{{ site.getSeason }}"

It works if the field in a text field (it has the value 76 as default), but not with a number type.
Is there a problem with my variable not being considered as a number?

Thank you and have a nice day.

String templates aka query language are not supported for most default values. What you could do is create your own number field in plugin:
PHP:

Kirby::plugin('my/plugin', [
	'siteMethods' => [
		'getSeason' => function () {
			return 5;
			},
	],
	'fields' => [
		'num' => [
			'extends' => 'number',
			'props' => [
				'default' => function ($default = null) {
					return $this->toNumber($this->model->toSafeString($default) ?? '');
				},
			]
		]
	]
]);

JS: index.js

panel.plugin("my/plugin", {
    fields: {
        num: {
            extends: "k-number-field"
        }
    }
});

Yaml:

    fields:
      season:
        type: num
        default: "{{ site.getSeason }}"

The above refers to Kirby 3 + 4, just noticed that according to the category you have chosen you still seem to be on Kirby 2, is that correct?

For Kirby 2, I can’t remember, it’s no longer supported.

It works like a charm, I need to dive into plugin creation…
Thanks for the help and the explanation !