Update specific structure field

I want to update a specific structure entry. I have tried with that function but it only appends the items to the structure field. Is there a way I can update a specific one?

Example using Starterkit social field:

$structure = $page->social()->yaml();
$item = $structure[0];
$item['platform'] = 'New Value';
$structure[0] = $item;

dump($structure);
1 Like

I’ve adapted your example to try and update a structure field on a site I’m working on.

See my code below:

try {
         $structure = page('home')->heroContent()->yaml();


          foreach ($structure as $item) {
             $publishDate = new DateTime($item['publishdate']);
             $todaysDate = new DateTime();

               if ($todaysDate >= $publishDate) {
                  $item['publish'] = 'true';
                } else {
                  $item['publish'] = 'false';
                }
             }

                $home = page('home')->update(array('heroContent' => $structure));

                return true;
             } catch (Exception $e) {
                return $e->getMessage();
            }

I’ve checked and the if statement if passing as true. However I’m unsure how to apply the “new” structure to the heroContent field.

@texnixe Would you be able to advise on this?