Answers.Body: <p>Got it!</p>
  
  <p>In case you just want to add lines (or Blocks) to a SuperTable field of an entry, no need to update the entry itself, you "just" have to create new Blocks with correct type, field and entry.</p>
  
  <pre><code>    $field = craft()-&gt;fields-&gt;getFieldByHandle('mySuperTableField');
      $blockTypes = craft()-&gt;superTable-&gt;getBlockTypesByFieldId($field-&gt;id);
      $blockType = $blockTypes[0]; //Only 1 Type of Blocks in the SuperTable
      $typeId = $blockType['id'];
  
      $block = new SuperTable_BlockModel();
      $block-&gt;fieldId = $field-&gt;id;
      $block-&gt;typeId = $typeId;
      $block-&gt;ownerId = $entryId; //this is the entry id
  
      $block-&gt;setContentFromPost(array(
          'categoryOne' =&gt; [$catOne-&gt;id],
          'categoryTwo' =&gt; [$catTwo-&gt;id],
          'textField' =&gt; 'blablable...'
      ));
  
      $success = craft()-&gt;superTable-&gt;saveBlock($block);
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-09-11T10:02:10.033Z
Answers.LastActivityDate: 2019-09-11T10:02:10.033Z
Answers.UserDisplayName: 20100
Body: <p>I am trying to add new lines into a SuperTable field of an entry from my plugin.
  Following the <a href="https://verbb.io/craft-plugins/super-table/v1/docs/guides/developer-examples#programatically-saving-a-super-table-field-with-content" rel="nofollow noreferrer">Developper sample</a>, I am able to change set lines to this SuperTable field.
  But it is replacing the existing content.
  What should I do to be able to keep existing lines in my SuperTable and add new ones?
  Thanks for your help!</p>
  
Tags: <plugin-development><craft2><plugin-supertable>
Title: Programatically add lines to a Super Table field
ThreadText: # Programatically add lines to a Super Table field
  
  (Asked by: username_0 on 2019-09-11)
  
  I am trying to add new lines into a SuperTable field of an entry from my plugin.
  Following the [Developper sample](https://verbb.io/craft-plugins/super-table/v1/docs/guides/developer-examples#programatically-saving-a-super-table-field-with-content), I am able to change set lines to this SuperTable field.
  But it is replacing the existing content.
  What should I do to be able to keep existing lines in my SuperTable and add new ones?
  Thanks for your help!
  
  **Tags:** plugin-development, craft2, plugin-supertable
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2019-09-11. Score: 1
  
  Got it!
  
  In case you just want to add lines (or Blocks) to a SuperTable field of an entry, no need to update the entry itself, you "just" have to create new Blocks with correct type, field and entry.
  
  ```
      $field = craft()->fields->getFieldByHandle('mySuperTableField');
      $blockTypes = craft()->superTable->getBlockTypesByFieldId($field->id);
      $blockType = $blockTypes[0]; //Only 1 Type of Blocks in the SuperTable
      $typeId = $blockType['id'];
  
      $block = new SuperTable_BlockModel();
      $block->fieldId = $field->id;
      $block->typeId = $typeId;
      $block->ownerId = $entryId; //this is the entry id
  
      $block->setContentFromPost(array(
          'categoryOne' => [$catOne->id],
          'categoryTwo' => [$catTwo->id],
          'textField' => 'blablable...'
      ));
  
      $success = craft()->superTable->saveBlock($block);
  
  ```
  
  
  ---
  
  