title: Play! Framework 2.0 - Looping through a map in a scala template?
body: <p>I have a map representing a table of contents, it contains <code>Chapter</code> keys and <code>List[Section]</code> values. Right now I am trying to loop through this in my template like this:</p>
  
  <pre><code>&lt;dl&gt;
  @table_of_contents.foreach((e) =&gt; {
      &lt;dt&gt;
          @e._1.title
      &lt;/dt&gt;
          for(section &lt;- e._2){
          &lt;dd&gt;
              @section.title
          &lt;/dd&gt;
          }
  })
  &lt;/dl&gt;
  </code></pre>
  
  <p>I currently get no output in the <code>&lt;dl&gt;</code> however.</p>
  
  <p>I added a <code>println(table_of_contents)</code> statement to the top of the template to ensure that the map did in fact have data and it printed:</p>
  
  <p><code>{models.Chapter@1=BeanList size[4] hasMoreRows[false] list[models.Section@1, models.Section@2, models.Section@3, models.Section@4], models.Chapter@2=BeanList size[0] hasMoreRows[false] list[]}</code></p>
  
  <p>perhaps I need to use an imperative style?</p>
  
  <p>UPDATE:</p>
  
  <p>Still working on this... got this variation to compile but no output. </p>
  
  <pre><code>&lt;dl&gt;
  @table_of_contents.foreach{case(a, b) =&gt; {
      &lt;dt&gt;
          @a.title
      &lt;/dt&gt;
          @displaySections(b)
  }}
  &lt;/dl&gt;
  
  ...
  
  @displaySections(sections: List[Section]) = {
    @for(a_section &lt;- sections) {
          &lt;dd&gt;@a_section.title&lt;/li&gt;
    }
  }
  </code></pre>