Answers.Body: <p>There's an example of this in the Twig documentation: <a href="https://twig.symfony.com/doc/3.x/tags/for.html#iterating-over-keys-and-values" rel="nofollow noreferrer">https://twig.symfony.com/doc/3.x/tags/for.html#iterating-over-keys-and-values</a></p>
  
  <p>In your example, it would be:</p>
  
  <pre><code>{% for key, value in hash %}
      &lt;span class="{{ key }}"&gt;{{ value }}&lt;/span&gt;
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-01-14T21:55:51.460Z
Answers.Text: Thanks Brad :thumbsup:
Answers.UserDisplayName: Jonathan Schofield
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-01-14T19:36:43.280Z
Answers.LastActivityDate: 2020-01-14T19:36:43.280Z
Answers.UserDisplayName: Brad Bell
Body: <p>This is possibly more of a Twig thing, but if I have a hash…</p>
  
  <pre><code>{% set hash = {
      "key": "value"
  } %}
  </code></pre>
  
  <p>How can I output the <strong>key name</strong>?</p>
  
  <pre><code>{% for value in hash %}
      &lt;span class="{{ key }}"&gt;{{ value }}&lt;/span&gt;
  {% endfor %}
  </code></pre>
  
Tags: <hash>
Title: Get a hash’s key name
ThreadText: # Get a hash’s key name
  
  (Asked by: username_0 on 2020-01-14)
  
  This is possibly more of a Twig thing, but if I have a hash…
  
  ```
  {% set hash = {
      "key": "value"
  } %}
  
  ```
  
  How can I output the **key name**?
  
  ```
  {% for value in hash %}
      <span class="{{ key }}">{{ value }}</span>
  {% endfor %}
  
  ```
  
  **Tags:** hash
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-01-14. Score: 1
  
  There's an example of this in the Twig documentation: <https://twig.symfony.com/doc/3.x/tags/for.html#iterating-over-keys-and-values>
  
  In your example, it would be:
  
  ```
  {% for key, value in hash %}
      <span class="{{ key }}">{{ value }}</span>
  {% endfor %}
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks username_1 :thumbsup:  
  
  ---
  
  