Answers.Body: <p>You'll need to loop through the fields in the blocktype definition for your Matrix field. For simplicities sake, I've supplied a loop, which you can cut-down if you have a specific block type in mind you just want to fetch for:</p>
  
  <pre><code>$matrixField = Craft::$app-&gt;getFields()-&gt;getFieldByHandle('myMatrixFieldHandle');
  
  foreach ($matrixField-&gt;getBlockTypes() as $key =&gt; $blockType) {
      Craft::dump($blockType-&gt;name);
  
      foreach ($blockType-&gt;getFields() as $key =&gt; $field) {
          Craft::dump($field-&gt;name);
      }
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-09-10T13:52:22.857Z
Answers.LastActivityDate: 2019-09-10T13:52:22.857Z
Answers.UserDisplayName: crawf
Body: <p>I have a matrix field that has a Supertable matrix within it.</p>
  
  <p>I need to programatically get the ID of the field that is nested in the Matrix.</p>
  
  <p>I have the code below:</p>
  
  <pre><code>$matrixField = Craft::$app-&gt;getFields()-&gt;getFieldByHandle('myMatrixFieldHandle');
  </code></pre>
  
  <p>Which gets me my Matrix field element, but I can't figure out how to get the fields that are within that Matrix field and thus the ID of the field within the Matrix field.</p>
  
  <p>Any help appreciated!</p>
  
Tags: <plugin-development><craft3><matrix><plugin-supertable>
Title: Module Development - Get ID of a field within a Matrix field
ThreadText: # Module Development - Get ID of a field within a Matrix field
  
  (Asked by: username_0 on 2019-07-23)
  
  I have a matrix field that has a Supertable matrix within it.
  
  I need to programatically get the ID of the field that is nested in the Matrix.
  
  I have the code below:
  
  ```
  $matrixField = Craft::$app->getFields()->getFieldByHandle('myMatrixFieldHandle');
  
  ```
  
  Which gets me my Matrix field element, but I can't figure out how to get the fields that are within that Matrix field and thus the ID of the field within the Matrix field.
  
  Any help appreciated!
  
  **Tags:** plugin-development, craft3, matrix, plugin-supertable
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-09-10. Score: 1
  
  You'll need to loop through the fields in the blocktype definition for your Matrix field. For simplicities sake, I've supplied a loop, which you can cut-down if you have a specific block type in mind you just want to fetch for:
  
  ```
  $matrixField = Craft::$app->getFields()->getFieldByHandle('myMatrixFieldHandle');
  
  foreach ($matrixField->getBlockTypes() as $key => $blockType) {
      Craft::dump($blockType->name);
  
      foreach ($blockType->getFields() as $key => $field) {
          Craft::dump($field->name);
      }
  }
  
  ```
  
  
  ---
  
  