Answers.Body: <p>Looping through a Matrix field is pretty easy, here is an example. Also read the docs on the Matrix field here - <a href="https://craftcms.com/docs/matrix-fields" rel="nofollow noreferrer">https://craftcms.com/docs/matrix-fields</a></p>
  
  <pre><code>{% for block in entry.myMatrix %}
      {% set handle = block.type.handle %} {# Grab the current block handle #}
  
      {{ handle }} {# Echo out the handle #}
  
      {% if handle == 'myMatrixBlock' %}
          {{ myMatrixBlock.heading }}  {# If you have a field called heading in myMatrixBlock #}
      {% endif %}
  
  {% endfor %}
  </code></pre>
  
  <hr>
  
  <p><strong>Updated</strong> </p>
  
  <p>Take a look at these examples...</p>
  
  <p><a href="https://craftcms.stackexchange.com/questions/5346/getting-fields-of-a-section-getfields">getting fields of a section (getFields())</a></p>
  
  <p><a href="https://craftcms.stackexchange.com/questions/11068/how-to-loop-through-matrix-block-fields-and-pull-out-handle-and-content">How to loop through matrix block fields and pull out handle and content?</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-19T04:13:22.497Z
Answers.Text: I know how to get it when I know the fields. I want to get the fields programatically. In the example you give, I'd like to get `heading` programatically. Do you know how to do it?
Answers.UserDisplayName: user2997606
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-08-18T06:04:01.797Z
Answers.LastActivityDate: 2016-08-20T02:50:15.877Z
Answers.LastEditDate: 2017-04-13T12:51:00.253Z
Answers.UserDisplayName: Fyrebase
Body: <p>How can I get the fields of a matrix field? I want to loop through the fields. I have the fields of the section, if the <code>field.handle</code> is of type matrix, I want to get the fields of the matrix.</p>
  
Tags: <plugin-development><matrix>
Title: Getting fields of Matrix?
ThreadText: # Getting fields of Matrix?
  
  (Asked by: username_0 on 2016-08-18)
  
  How can I get the fields of a matrix field? I want to loop through the fields. I have the fields of the section, if the `field.handle` is of type matrix, I want to get the fields of the matrix.
  
  **Tags:** plugin-development, matrix
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-08-18. Score: 5 | Accepted answer
  
  Looping through a Matrix field is pretty easy, here is an example. Also read the docs on the Matrix field here - <https://craftcms.com/docs/matrix-fields>
  
  ```
  {% for block in entry.myMatrix %}
      {% set handle = block.type.handle %} {# Grab the current block handle #}
  
      {{ handle }} {# Echo out the handle #}
  
      {% if handle == 'myMatrixBlock' %}
          {{ myMatrixBlock.heading }}  {# If you have a field called heading in myMatrixBlock #}
      {% endif %}
  
  {% endfor %}
  
  ```
  
  ---
  
  **Updated**
  
  Take a look at these examples...
  
  [getting fields of a section (getFields())](https://craftcms.stackexchange.com/questions/5346/getting-fields-of-a-section-getfields)
  
  [How to loop through matrix block fields and pull out handle and content?](https://craftcms.stackexchange.com/questions/11068/how-to-loop-through-matrix-block-fields-and-pull-out-handle-and-content)
  
  > **Comments:**
  > **username_0**: I know how to get it when I know the fields. I want to get the fields programatically. In the example you give, I'd like to get `heading` programatically. Do you know how to do it?  
  
  ---
  
  