Answers.Body: <p>Not sure what you want to do with the fields, but you can access them through fieldLayout.</p>
  
  <pre><code>{% for block in entry.myMatrixField %}
  
      {% for field in block.getFieldLayout().getFields() %}
  
          {# get properties #}
          {{ field.getField().name }}
          {{ field.getField().handle }}
          {{ field.getField().id }}
  
          {# get value #}
          {% set handle = field.getField().handle %}
          {{ block[handle] }}
  
      {% endfor %}
  
  {% endfor %}
  </code></pre>
  
  <p>You do kind of need to know what the field types are, in order to know how to display them. <code>{{ block[handle] }}</code> will fail for instance if one of the fields is an 'Entry' field, because you can't convert an ElementCriteriaModel to a string. To check the field type you can use <code>field.getField().type</code>;</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-03T20:30:45.923Z
Answers.Text: It's a bit more verbose than I was hoping for, but does what I need. Thank you.
Answers.UserDisplayName: ray
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-03T21:18:01.777Z
Answers.Text: Get rid of the extra junk and it's just 5 lines! Fyi... see [this answer](http://craftcms.stackexchange.com/a/6964/784) for more complete example.
Answers.UserDisplayName: Douglas McDonald
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-03T22:22:32.723Z
Answers.Text: I just meant that `block[block.getFieldLayout().getFields()[0].getField().handle]` seems like a long dig to get to the value.
Answers.UserDisplayName: ray
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-02T23:34:30.903Z
Answers.LastActivityDate: 2015-02-02T23:41:41.343Z
Answers.LastEditDate: 2015-02-02T23:41:41.343Z
Answers.UserDisplayName: Douglas McDonald
Body: <p>Is there a way to dynamically iterate over a matrix block's fields such that the template doesn't need to know the field handles? This doesn't work:</p>
  
  <pre><code>{% for block in entry.myMatrixField %}
      {% for field in block %}
          {# do something with field #}       
      {% endfor %}
  {% endfor %}
  </code></pre>
  
  <p>This seems like a simple thing to want to do but I haven't figured out a way to do it.</p>
  
Tags: <matrix><field>
Title: Dynamically iterate over a matrix block's fields?
ThreadText: # Dynamically iterate over a matrix block's fields?
  
  (Asked by: username_0 on 2015-02-02)
  
  Is there a way to dynamically iterate over a matrix block's fields such that the template doesn't need to know the field handles? This doesn't work:
  
  ```
  {% for block in entry.myMatrixField %}
      {% for field in block %}
          {# do something with field #}       
      {% endfor %}
  {% endfor %}
  
  ```
  
  This seems like a simple thing to want to do but I haven't figured out a way to do it.
  
  **Tags:** matrix, field
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-02-02. Score: 5 | Accepted answer
  
  Not sure what you want to do with the fields, but you can access them through fieldLayout.
  
  ```
  {% for block in entry.myMatrixField %}
  
      {% for field in block.getFieldLayout().getFields() %}
  
          {# get properties #}
          {{ field.getField().name }}
          {{ field.getField().handle }}
          {{ field.getField().id }}
  
          {# get value #}
          {% set handle = field.getField().handle %}
          {{ block[handle] }}
  
      {% endfor %}
  
  {% endfor %}
  
  ```
  
  You do kind of need to know what the field types are, in order to know how to display them. `{{ block[handle] }}` will fail for instance if one of the fields is an 'Entry' field, because you can't convert an ElementCriteriaModel to a string. To check the field type you can use `field.getField().type`;
  
  > **Comments:**
  > **username_0**: It's a bit more verbose than I was hoping for, but does what I need. Thank you.  
  > **username_1**: Get rid of the extra junk and it's just 5 lines! Fyi... see [this answer](http://craftcms.stackexchange.com/a/6964/784) for more complete example.  
  > **username_0**: I just meant that `block[block.getFieldLayout().getFields()[0].getField().handle]` seems like a long dig to get to the value.  
  
  ---
  
  