gork
1
Heya
quick question: is it possible to create defaults in nested structures?
I know of
emails:
label: Emails
type: structure
default:
- email: bastian@getkirby.com
- email: lukas@getkirby.com
- email: nico@getkirby.com
- email: sonja@getkirby.com
fields:
email:
label: Email
type: email
But how do I achieve this for nested lists?
Thanks
I don’t think thats possible, you could, prefill the structure at page creation using a hook.
gork
3
Just for future reference, here’s what I did for a nested structure
# blueprint
attributes:
label: Attributes
type: structure
translate: false
fields:
autoid:
type: hidden
translate: false
block:
label: Block
type: text
items:
label: Attribute
type: structure
fields:
autoid:
type: hidden
translate: false
block:
label: Block
type: text
# config.php
return [
'hooks' => [
'page.create:after' => function ($page, $input) {
if($page->intendedTemplate() == 'model') {
$site = $this->site();
$_attributes = $site->find('products')->attributes()->yaml();
foreach ($_attributes as $akey => $block) {
unset($_attributes[$akey]['autoid']);
foreach ($block['items'] as $bkey => $items) {
unset($_attributes[$akey]['items'][$bkey]['autoid']);
$_attributes[$akey]['items'][$bkey]['name'] = '';
}
}
$page->update(['attributes' => yaml::encode($_attributes)]);
}
}
]
];
afaik it could’ve been done without unseting autoid or setting name to be an empty string, but I prefer a clean .txt file