title: Create a navigation menu using Twig
body: <p>How do you create a navigation menu using Twig?  Note that I am not using Sympony2.</p>
  
  <p>Given the following array passed to a Twig template:</p>
  
  <pre><code>$menu_main=array(
      'active'=&gt;2,
      'menu'=&gt;array(
          array('components_id'=&gt;2,'name'=&gt;'First Link','newwindow'=&gt;0),
          array('components_id'=&gt;3,'name'=&gt;'Second Link','newwindow'=&gt;0),
          array('components_id'=&gt;7,'name'=&gt;'Third Link','newwindow'=&gt;1),
          array('components_id'=&gt;8,'name'=&gt;'Forth Link','newwindow'=&gt;0)
      )
  );
  </code></pre>
  
  <p>I am trying to create the following navigation menu:</p>
  
  <pre><code>&lt;ul&gt;
      &lt;li class="first active"&gt;&lt;a href="index.php?cid=2"&gt;First Link&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href="index.php?cid=3"&gt;Second Link&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href="index.php?cid=7" target="_blank"&gt;Third Link&lt;/a&gt;&lt;/li&gt;
      &lt;li class="last"&gt;&lt;a href="index.php?cid=8"&gt;Forth Link&lt;/a&gt;&lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>Below is my non-working attempt:</p>
  
  <pre><code>{#
  menu_main is an associated array containing active key and menu key.
  menu is an associated array of containing name, components_id, and whether it should open a new window
  #}
  &lt;ul&gt;
      {% for item in menu_main.menu %}
      &lt;li
      {% if item.components_id == menu_main.active %}
      class="active"
      {# How do I add first and last class?  Maybe using length? #}
      {% endif%}&gt;
      &lt;a href="{{ item[0] }}"&gt;{{item[1]}}{% if item.newwindow %} target="_blank" {% endif%}&gt;&lt;/a&gt;
      &lt;/li&gt;
      {% endfor %}
  &lt;/ul&gt;
  </code></pre>