title: Iterating over key-value arrays in Twig?
body: <p>I'm (finally) switching my site from Drupal7 to Symfony3.</p>
  
  <p>I'm working on migrating my layout to .twig.</p>
  
  <p>I've got a question about loops and key-value arrays.</p>
  
  <p>I've configured a k/v array</p>
  
  <pre><code>{% set test = {
          sec1: {
              title:   "title 1",
              content: "content 1"
          },
          sec2: {
              title:   "title 2",
              content: "content 2"
          },
      }
  %}
  </code></pre>
  
  <p>I can reference any specific array element in other markup.  E.g., this works as intended</p>
  
  <pre><code>&lt;ul&gt;
      &lt;li&gt;
          &lt;h1&gt;{{ test.sec1.title }}&lt;/h1&gt;
          &lt;div&gt;
              &lt;p&gt;{{ test.sec1.content }}&lt;/p&gt;
          &lt;/div&gt;
      &lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>Now I want to loop/repeat the block over a count of n.  But trying this,</p>
  
  <pre><code>&lt;ul&gt;
  {% for i in 1..5 %}
      &lt;li&gt;
          &lt;h1&gt;{{ test.sec{{ i }}.title }}&lt;/h1&gt;
          &lt;div&gt;
              &lt;p&gt;{{ test.sec{{ i }}.content }}&lt;/p&gt;
          &lt;/div&gt;
      &lt;/li&gt;
  {% endfor %}
  &lt;/ul&gt;
  </code></pre>
  
  <p>fires an error</p>
  
  <pre><code>Unexpected token "punctuation" of value "{" ("end of print statement" expected) in default/index.html.twig at line 67.
  500 Internal Server Error - Twig_Error_Syntax
  </code></pre>
  
  <p>I've been working with variations of these</p>
  
  <pre><code>http://twig.sensiolabs.org/doc/tags/for.html#iterating-over-keys
  </code></pre>
  
  <p>but can't get anything to work yet.</p>
  
  <p>What's the right way to loop this list over the secN's in the key-value array? </p>