I’d like to update a structure field inside a hook after my page was updated. I read a lot of threads here in the forum to exactly this question but don’t get it work.
This is my hook with some sample content to update. The structure field has two simple text fields at the moment, which I’d like to fill with sample content. What am I missing?
'page.update:after' => function ($newPage, $oldPage) {
if($newPage->intendedTemplate() == "mytemplate") {
$items = $newPage->myfield()->yaml();
foreach($items as &$item) {
$item['field01'] = 'Testcontent';
$item['field02'] = 'More Testcontent';
}
$newPage->update(['items' => Data::encode($items, 'yaml')]);
}