2014-12-19 75 views
0

我試圖做古老的畫廊循環計數器使用玉(我是一個新手)。我使用Twitter的引導,所以我需要把圖像與COL-MD-3爲一類,並與排一個di​​v的子div的」所以,理想情況是這樣的:循環與計數器

<div class="row"> 
    <div class="col-md-3">image goes here</div> 
    <div class="col-md-3">image goes here</div> 
    <div class="col-md-3">image goes here</div> 
    <div class="col-md-3">image goes here</div> 
</div> 
<div class="row"> 
    <div class="col-md-3">image goes here</div> 
    <div class="col-md-3">image goes here</div> 
    <div class="col-md-3">image goes here</div> 
    <div class="col-md-3">image goes here</div> 
</div> 

當我被困在是如何初始化一個新行,因爲在玉壓痕事項下面就是我開始,我該如何進行

div.row 
    each product, index in collection.products 
     div.col-md-3: img 

我會假設你會使用這樣的:?

if index % 3 
    div.row 

...但它不覺得退出e right ...

回答

0

解決了它走向不同的方向。我在我的views.py文件的頂部創建了一個context_processor,並將它作爲函數提供給我的模板。

views.py

@app.context_processor 
def utility_processor(): 
    def subdivide_list(list_to_group, group_size): 
     return [list_to_group[i:i+group_size] for i in range(0, len(list_to_group), group_size)] 
return dict(subdivide_list=subdivide_list) 

gallery.jade

div.col-md-9 
    for product_row in subdivide_list(all_products, 4) 
     div.row 
      for product in product_row 
       img(src="{{ url_for('static', filename='uploads/images/products/'+product.image.name_thumb) }}")