I think the problem result from your very manual approach to saving the content. Why don’t you use Kirby’s $page->update()
method? Also, you should be yaml-encoding the array you store in the structure field, see the addToStructure()
method for example here: Add To Structure not working