Answers.Body: <p>Assuming you have an entry to work with, something like this should work:</p>
  <pre><code>{% for block in entry.myMatrixFieldHandle if block.type == &quot;employment&quot; %}
      &lt;select&gt;
          {% for option in block.myDropDownFieldHandle.options %}        
              &lt;option value=&quot;{{ option.value }}&quot;&gt;{{ option.label }}&lt;/option&gt;
          {% endfor %}
      &lt;/select&gt;
  {% endfor %}
  </code></pre>
  <p>Otherwise you may need to get the field through the fieldLayout or by it's handle.</p>
  <p><strong>Update</strong></p>
  <p><code>craft.matrix</code> is not exposed to twig like it is in php. To get the dropdown field options through the matrix field directly you'll have to go the long way around (matrix &gt; blocktypes &gt; blocktype &gt; fields &gt; field &gt; options)</p>
  <pre><code>{% set matrixField = craft.fields.getFieldByHandle('employmentMatrix') %}
  {% set blockTypes = matrixField.getFieldType.getSettings.getBlockTypes %}
  {% for blockType in blockTypes if blockType.handle == &quot;myBlockTypeHandle&quot; %}
      {% for field in blockType.getFields() %}
          {% if field.handle == &quot;myDropDownFieldHandle&quot; %}
              &lt;select&gt;
                  {% for option in field.settings.options %}
                      &lt;option value=&quot;{{ option.value }}&quot;&gt;{{ option.label }}&lt;/option&gt;
                  {% endfor %}
              &lt;/select&gt;
          {% endif %}
      {% endfor %}
  {% endfor %}
  </code></pre>
  <p>UPDATE: This is for craft 2. For craft 3 see Nathan S answer below.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-14T18:10:14.350Z
Answers.Text: Thanks for the feedback but this is not what I'm after, please see my update above.
Answers.UserDisplayName: Matt V
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-15T17:26:10.820Z
Answers.Text: See if that works better (my brain hurts).
Answers.UserDisplayName: Douglas McDonald
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-04-27T10:07:29.577Z
Answers.Text: That saved me a real headache, thanks! Could be a little shortened by adding the condition directly to the for loop. E.g.: `{% for blockType in blockTypes if blockType.handle == "myBlockTypeHandle" %}`
Answers.UserDisplayName: medoingthings
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-04-29T03:29:38.047Z
Answers.Text: @medoingthings: Shortened and fixed ;) Glad it helped.
Answers.UserDisplayName: Douglas McDonald
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-16T15:50:22.963Z
Answers.Text: This kind of stuff really needs to be in the Craft documentation. Thank you for your contribution, it just got me out of a real jam.
Answers.UserDisplayName: JxM
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-17T21:33:19.993Z
Answers.Text: @JonMack Glad it helped. fyi... you might want to check out the 'inspector' plugin. It's really good for printing out objects (and all the methods, properties) in your templates to "follow the rabbit hole" so to speak. Can also use {{ dump(obj) }} but it's not quite as easy to read/follow.
Answers.UserDisplayName: Douglas McDonald
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2015-04-14T17:19:10.370Z
Answers.LastActivityDate: 2021-01-28T05:37:30.113Z
Answers.LastEditDate: 2021-01-28T05:37:30.113Z
Answers.UserDisplayName: Douglas McDonald
Answers.Body: <p>Craft 3 updated the code so this is the new way to get a matrix field that worked for me. The only difference is <code>matrixField.blockTypes</code> vs Craft 2 <code>matrixField.getFieldType.getSettings.getBlockTypes</code></p>
  
  <pre><code> {% set matrixField = craft.fields.getFieldByHandle('employmentMatrix') %}
          {% set blockTypes = matrixField.blockTypes %}
          {% for blockType in blockTypes %}
              {% if blockType.handle == "myBlockTypeHandle" %}
                  {% for field in blockType.getFields() %}
                      {% if field.handle == "myDropDownFieldHandle" %}
                          &lt;select&gt;
                              {% for option in field.settings.options %}
                                  &lt;option value="{{ option.value }}"&gt;{{ option.label }}&lt;/option&gt;
                              {% endfor %}
                          &lt;/select&gt;
                      {% endif %}
                  {% endfor %}
              {% endif %}
          {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-08-05T10:08:01.240Z
Answers.Text: Has anyone done similar yet for Craft 4?
Answers.UserDisplayName: mmc501
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-05-07T15:44:45.137Z
Answers.LastActivityDate: 2020-05-07T15:44:45.137Z
Answers.UserDisplayName: Nathan S
Answers.Body: <p>There's an error in Douglas McDonald's answer, here is the correction:</p>
  
  <pre><code>        {% set matrixField = craft.fields.getFieldByHandle('employmentMatrix') %}
          {% set blockTypes = matrixField.getFieldType.getSettings.getBlockTypes %}
          {% for blockType in blockTypes %}
              {% if blockType.handle == "myBlockTypeHandle" %}
                  {% for field in blockType.getFields() %}
                      {% if field.handle == "myDropDownFieldHandle" %}
                          &lt;select&gt;
                              {% for option in field.settings.options %}
                                  &lt;option value="{{ option.value }}"&gt;{{ option.label }}&lt;/option&gt;
                              {% endfor %}
                          &lt;/select&gt;
                      {% endif %}
                  {% endfor %}
              {% endif %}
          {% endfor %}
  </code></pre>
  
  <p>The error was, in order to access a field's options you have to do this:</p>
  
  <pre><code>... field.settings.options NOT field.options
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-04-29T03:30:56.657Z
Answers.Text: Thanks Matt V. Somehow I missed your comment way back when. All fixed.
Answers.UserDisplayName: Douglas McDonald
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-22T14:34:02.037Z
Answers.LastActivityDate: 2015-04-22T14:34:02.037Z
Answers.UserDisplayName: Matt V
Body: <p>I have a matrix field with a block called "employment", under this block are fields, one of those fields is a drop down.</p>
  
  <p>I'd like to be able to output the drop down field as a select list so users can choose from it. </p>
  
  <p><em>Note: that I'm NOT trying to output what a user has selected, I just want to output the options from which a user can select.</em></p>
  
  <p>Thanks!</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>That's not really what I'm after. Let me be more clear.</p>
  
  <p>The matrix field I'm speaking of is attached to the user model but I'm not trying to output the user's data saved for the matrix. What I'm trying to do is simply output a field of a given matrix.</p>
  
  <p>I am able to load the matrix doing this:</p>
  
  <pre><code>{% set matrix = craft.fields.getFieldByHandle('employmentMatrix') %}
  </code></pre>
  
  <p>But I'm not sure how to access the matrix's blocks then fields. I tried this:</p>
  
  <pre><code>{% set matrix = craft.fields.getFieldByHandle('employmentMatrix') %}
  
  {% set blocks = craft.matrix.getBlockTypesByFieldId(matrix.id) %}
  </code></pre>
  
  <p>But I get an error saying "matrix" is not a method.</p>
  
Tags: <templating><matrix>
Title: Output matrix field data
ThreadText: # Output matrix field data
  
  (Asked by: username_0 on 2015-04-14)
  
  I have a matrix field with a block called "employment", under this block are fields, one of those fields is a drop down.
  
  I'd like to be able to output the drop down field as a select list so users can choose from it.
  
  *Note: that I'm NOT trying to output what a user has selected, I just want to output the options from which a user can select.*
  
  Thanks!
  
  **UPDATE**
  
  That's not really what I'm after. Let me be more clear.
  
  The matrix field I'm speaking of is attached to the user model but I'm not trying to output the user's data saved for the matrix. What I'm trying to do is simply output a field of a given matrix.
  
  I am able to load the matrix doing this:
  
  ```
  {% set matrix = craft.fields.getFieldByHandle('employmentMatrix') %}
  
  ```
  
  But I'm not sure how to access the matrix's blocks then fields. I tried this:
  
  ```
  {% set matrix = craft.fields.getFieldByHandle('employmentMatrix') %}
  
  {% set blocks = craft.matrix.getBlockTypesByFieldId(matrix.id) %}
  
  ```
  
  But I get an error saying "matrix" is not a method.
  
  **Tags:** templating, matrix
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_1 on 2015-04-14. Score: 9
  
  Assuming you have an entry to work with, something like this should work:
  
  ```
  {% for block in entry.myMatrixFieldHandle if block.type == "employment" %}
      <select>
          {% for option in block.myDropDownFieldHandle.options %}        
              <option value="{{ option.value }}">{{ option.label }}</option>
          {% endfor %}
      </select>
  {% endfor %}
  
  ```
  
  Otherwise you may need to get the field through the fieldLayout or by it's handle.
  
  **Update**
  
  `craft.matrix` is not exposed to twig like it is in php. To get the dropdown field options through the matrix field directly you'll have to go the long way around (matrix > blocktypes > blocktype > fields > field > options)
  
  ```
  {% set matrixField = craft.fields.getFieldByHandle('employmentMatrix') %}
  {% set blockTypes = matrixField.getFieldType.getSettings.getBlockTypes %}
  {% for blockType in blockTypes if blockType.handle == "myBlockTypeHandle" %}
      {% for field in blockType.getFields() %}
          {% if field.handle == "myDropDownFieldHandle" %}
              <select>
                  {% for option in field.settings.options %}
                      <option value="{{ option.value }}">{{ option.label }}</option>
                  {% endfor %}
              </select>
          {% endif %}
      {% endfor %}
  {% endfor %}
  
  ```
  
  UPDATE: This is for craft 2. For craft 3 see username_4 answer below.
  
  > **Comments:**
  > **username_0**: Thanks for the feedback but this is not what I'm after, please see my update above.  
  > **username_1**: See if that works better (my brain hurts).  
  > **username_2**: That saved me a real headache, thanks! Could be a little shortened by adding the condition directly to the for loop. E.g.: `{% for blockType in blockTypes if blockType.handle == "myBlockTypeHandle" %}`  
  > **username_1**: @username_2: Shortened and fixed ;) Glad it helped.  
  > **username_3**: This kind of stuff really needs to be in the Craft documentation. Thank you for your contribution, it just got me out of a real jam.  
  > **username_1**: @JonMack Glad it helped. fyi... you might want to check out the 'inspector' plugin. It's really good for printing out objects (and all the methods, properties) in your templates to "follow the rabbit hole" so to speak. Can also use {{ dump(obj) }} but it's not quite as easy to read/follow.  
  
  ---
  
  ### Answer by username_4 on 2020-05-07. Score: 4
  
  Craft 3 updated the code so this is the new way to get a matrix field that worked for me. The only difference is `matrixField.blockTypes` vs Craft 2 `matrixField.getFieldType.getSettings.getBlockTypes`
  
  ```
   {% set matrixField = craft.fields.getFieldByHandle('employmentMatrix') %}
          {% set blockTypes = matrixField.blockTypes %}
          {% for blockType in blockTypes %}
              {% if blockType.handle == "myBlockTypeHandle" %}
                  {% for field in blockType.getFields() %}
                      {% if field.handle == "myDropDownFieldHandle" %}
                          <select>
                              {% for option in field.settings.options %}
                                  <option value="{{ option.value }}">{{ option.label }}</option>
                              {% endfor %}
                          </select>
                      {% endif %}
                  {% endfor %}
              {% endif %}
          {% endfor %}
  
  ```
  
  > **Comments:**
  > **username_5**: Has anyone done similar yet for Craft 4?  
  
  ---
  
  ### Answer by username_0 on 2015-04-22. Score: 4
  
  There's an error in username_1's answer, here is the correction:
  
  ```
          {% set matrixField = craft.fields.getFieldByHandle('employmentMatrix') %}
          {% set blockTypes = matrixField.getFieldType.getSettings.getBlockTypes %}
          {% for blockType in blockTypes %}
              {% if blockType.handle == "myBlockTypeHandle" %}
                  {% for field in blockType.getFields() %}
                      {% if field.handle == "myDropDownFieldHandle" %}
                          <select>
                              {% for option in field.settings.options %}
                                  <option value="{{ option.value }}">{{ option.label }}</option>
                              {% endfor %}
                          </select>
                      {% endif %}
                  {% endfor %}
              {% endif %}
          {% endfor %}
  
  ```
  
  The error was, in order to access a field's options you have to do this:
  
  ```
  ... field.settings.options NOT field.options
  
  ```
  
  > **Comments:**
  > **username_1**: Thanks username_0 V. Somehow I missed your comment way back when. All fixed.  
  
  ---
  
  