Add to structured data remove from structured data from the front end

I want to keep this simple because I can program the rest.

Lets say I have this value and two buttons. Add and remove.
How can I take cats. Either add it to my pages structured data from the frontend. Or remove it from the structured data on the frontend. -

My logic will be if $title(‘cats’) exists show remove if (‘cats’) doesn’t exist show add.

$title = “cats”;

|Button Add | | Button Remove |

label: Title
type: text

Check if an entry exists in the collection:

$items = $page->yaml_field()->structure();

$item = $items->findBy('title','cats');
if($item) {
  // do something

Add to structure:

    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();

Removing items: use unset[‘key’]

See this post: Delete fieldentry from frontend?

@bbarclay Did this solve your issue?

Yes, this helped a ton.