This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit

eZ Community » Forums » eZ Publish 5 Platform » 2 cols 2rows content grid in twig

2 cols 2rows content grid in twig

2 cols 2rows content grid in twig

Wednesday 08 May 2013 10:33:18 pm - 3 replies

Hi guys,

I'm trying to convert my old 4.x block templates into twig, and I'm having a little problem with rendering a 2 columns 2 rows block.

The old template looked like this:

{foreach $valid_nodes as $valid_node max 4}
        <div class="span4">
        {node_view_gui view='block_item' image_class='contentgrid' content_node=$valid_node}
        {delimiter modulo=2}
        <div class="row">

While I get the first part, I can't figure out, for the life of me, a way to render the {delimiter} part in twig. Anyone has an idea?

Wednesday 08 May 2013 10:46:57 pm

Hi Charles

There is no delimiter statement in Twig loops. However you can consider using the loop variable as described in Twig documentation.

So your template code would look like this:

{% for item in validItems %}
    <div class="span4">
    {{ render( 
                     'locationId': item.locationId, 
                     'viewType': 'block_item', 
                     'params': { 'image_class': 'contentgrid' }
         ) }}
    {% if loop.index % 2 %}
    <div class="row">
    {% endif %}
{% endfor %} 

Modified on Thursday 09 May 2013 7:56:00 am by Jérôme Vieilledent

Wednesday 08 May 2013 11:41:24 pm

Ah yes. Thanks a lot, Jérôme. The loop is exactly what I needed.

PS: just for the record, shouldn't the render part be delimited by {{ ... }} and not {% ... %}?

Modified on Wednesday 08 May 2013 11:45:59 pm by Charles Okech

Thursday 09 May 2013 7:45:21 am

Yes you're right. You need to use {{ }}, sorry. It was a bit late happy.gif Emoticon


You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from