Symfony2:如何渲染嵌套的foreach循环并限制内循环以创建图库?

How can I have a nested loop and then carry on from the previous loop?

Example:

{% for image in site_images[page.id].images %}
<div class="container">
    <div class="item">
        <img src="{{ image[loop.index0] }}" />
        <img src="{{ image[loop.index0] }}" />
        <img src="{{ image[loop.index0] }}" />
        <img src="{{ image[loop.index0] }}" />
    </div>
</div>
<div class="container">
    <div class="item">
        <img src="{{ image[loop.index0] }}" />
        <img src="{{ image[loop.index0] }}" />
        <img src="{{ image[loop.index0] }}" />
        <img src="{{ image[loop.index0] }}" />
    </div>
</div>
....
{% endfor %}

How can I make it show 4 images in the first .container > .item div, then come out create a new .container > .item div and carry on so it would be image[4]

You can use the batch filter:

{% for section in images|batch(4) %}

    <div class="container">
        <div class="item">

            {% for image in section %}
                <img src="{{ image }}" />
            {% endfor %}

        </div>
    </div>

{% endfor %}