2012-04-27 12 views
4

申し訳ありませんが、私はそのような配列を持っています。symfony2とtwig for onサブアレイ

[0] => Array (
    first_name => j, 
    last_name => b, 
    times => Array(
    [0] => Array(
     [in1] => a date here 
     [out1] => a date here 
     [in2] => a date here 
     [out2] => a date here 
    ) 
    [1] => Array(
     [in1] => another date here 
     [out1] => another date here 
     [in2] => another date here 
     [out2] => another date here 
    ))) 

私はSOのレイアウトのために、アレイの外観を簡略化してきました...

このリストには、多くの場合、時間はすべてが必要になります始まる配列に100種類以上の人々を持っています各「実体」は.timesサブを持っているので、私は助けを必要と私はそれを行うことができます罰金ですブラウザ... ..

{% for entity in entity %} 
<h3>{{ entity.first_name }} {{ entity.last_name }} ({{ start|date("m/d/Y") }} - {{ end|date("m/d/Y")}})</h3> 

<table = border="1" cellpadding="5" cellspacing="0"> 
     <thead> 
      <tr> 
       <th>Date</th> 
       <th>In</th> 
       <th>Lunch Out</th> 
       <th>Lunch In</th> 
       <th>Out</th> 
       <th>Extra In</th> 
       <th>Extra Out</th> 
       <th>Total Time</th> 
      </tr> 
     </thead> 
     <tbody> 
      {% for times in entity.times %} 
      <tr> 
       <td>{{ entity.times.daydate|date("M jS Y") }} </td> 
       <td>{{ entity.times.in1 is empty ? "" : entity.times.in1|date("h:i A") }}</td> 
       <td>{{ entity.times.out1 is empty ? "" : entity.times.out1|date("h:i A") }}</td> 
       <td>{{ entity.times.in2 is empty ? "" : entity.times.in2|date("h:i A") }}</td> 
       <td>{{ entity.times.out2 is empty ? "" : entity.times.out2|date("h:i A") }}</td> 
       <td>{{ entity.times.in3 is empty ? "" : entity.times.in3|date("h:i A") }}</td> 
       <td>{{ entity.times.out3 is empty ? "" : entity.times.out3|date("h:i A") }}</td> 
       <td>{{ entity.times.totaltime }} Hours</td> 
      </tr> 
      {% endfor%} 
     </tbody> 
</table> 
{% endfor %} 

私の現在の小枝コードでの出力は...、です配列もまたループする必要があります。それを行う正しい方法は何ですか?

答えて

3
{% for entity in entities %} 
    <h3>{{ entity.foo }}</h3> 

    {% for time in entity.times %} 
     <p>{{ time.bar }}</p> 
    {% endfor %} 
{% endfor %} 

あなたが探しているコンセプトがわかりやすくなるように、コードを簡略化しました。

+0

'

{{time.bar}}

'が新しくキャッシュされていません... – Justin

+0

実際には、私の問題ではありませんでした。 ..しかし、これは正確にそれを行う方法なので、私たちは将来の他の人々の参照のための答えを選択します。 – Justin

関連する問題