Tuesday, 15 March 2011

html - Twig loop grouping divs -



html - Twig loop grouping divs -

i want populate twig page info stored in database. utilize loop create multiple divs containing different entries of same tables. problem want grouping divs by4.. , cant stop loop when reach 4 step. in end big collon of divs. can please tell me how grouping divs 4?

this twig template:

<form method="post" id="form-book"> <section id="portfolio" class="container main"> <ul class="gallery col-4"> {% type in typeandrooms %} {% t, room in type %} <li> {% if t == 0 %} <div class="preview"> {% set var_id = 'bundles/twnelo/images/portfolio/thumb/item' %} {% set var_id = var_id ~ room.gettype.id %} {% set var_id = var_id ~ '.jpg' %} <img src="{{ asset(var_id) }}"> <div class="overlay"> </div> </div> <div class="desc"> <h5> {{ room.gettype.name }} </h5> <strong>beds: </strong>double bed<br/> <strong>available rooms: </strong> {{ type|length }} <br/> <strong>prices: </strong> {{ room.getprice }} <br/> <button type = "submit" name="singleapartment" value = "{{ room.gettype.id }}" class="btn btn-success btn-small">book room !</button> </div> {% endif %} {% if loop.index % 4 == 0 , loop.index > 0 %} </li> al 4-lea pas <li> {% endif %} </li> {% endfor %} {% endfor %} </ul> </section> </form> {% endfor %}

sorry useless space.. thats how used code

problem solved. new template:

<form method="post" id="form-book"> <section id="portfolio" class="container main"> <ul class="gallery col-4"> {% rooms in typesandrooms %} {% room in rooms %} {% if loop.index == 1 %} <li> <div class="preview"> {% set var_id = 'bundles/twnelo/images/portfolio/thumb/item' %} {% set var_id = var_id ~ room.gettype.id %} {% set var_id = var_id ~ '.jpg' %} <img src="{{ asset(var_id) }}"> <div class="overlay"> </div> </div> <div class="desc"> <h5> {{ room.gettype.name }} </h5> <strong>facilities: </strong>{% facility in room.getfacilities %} {% if loop.index < 4 %} {{ facility.getfacility }}; {% endif %} {% endfor %}<br/> <strong>available rooms: </strong> {{ rooms|length }} <br/> <strong>prices: </strong> {{ room.getprice }} lei <br/> <button type = "submit" name="singleapartment" value = "{{ room.gettype.id }}" class="btn btn-success btn-small">book room !</button> </div> </li> {% endif %} {% endfor %} {% endfor %} </ul> </section> </form>

you have open first row right before loop.

{% type in typeandrooms %} + <li> {% t, room in type %} - <li>

and close lastly 1 right after

{% endif %} - </li> {% endfor %} + </li> {% endfor %}

and given line {% if t==0 %} reckon you'll need utilize counter instead of index.loop. else end less 4 room per list row. best practice parse array first in controller , remove rooms t==0 remove {% if t==0 %} line in twig template , it'll work index.loop, want maintain logic in twig minimum.

html css symfony2 twig

No comments:

Post a Comment