# Structure field update

**URL:** <https://forum.getkirby.com/t/structure-field-update/7854>\
**Category:** Questions\
**Tags:** v2\
**Created:** [July 2, 2017, 3:38pm UTC](https://forum.getkirby.com/t/structure-field-update/7854 "2017-07-02T15:38:28Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [July 2, 2017, 3:50pm UTC](https://forum.getkirby.com/t/structure-field-update/7854/2 "2017-07-02T15:50:34Z")

</div>

Here’s an example function:

```php
    /**
     * Add a new element to a kirby structure field
     * @param string $page
     * @param string $field
     * @param array $data
     */
    function addToStructure($page, $field, $data = array()){
      $fieldData = page($page)->$field()->yaml();
      $fieldData[] = $data;
      $fieldData = yaml::encode($fieldData);
      try {
        page($page)->update(array($field => $fieldData));
        return true;
      } catch(Exception $e) {
        return $e->getMessage();
      }
    }

```

---

_[View the full topic](https://forum.getkirby.com/t/structure-field-update/7854)._
