2013-01-21 47 views
2

我想總計數resuslt。我已經做到了像總組結果,並在總成績中的一個產品....計數在沒有圈的樹枝上

,如: -

總產品的組= 15

在一組展示36產品。

第二組顯示56個產品。

我要顯示總組積結果= 36 + 56 => 92 而不for循環。

樹枝文件:

<table> 
<h2> Showing {{ templates | length }} Products</h2> 

    {% for groupResults in templates %} 
     {% if groupResults.doclist.docs[0].first_product_name is defined %} 


      Show all {{ groupResults | length }} results 



     <tr> 
      <td> 
      {{ groupResults.doclist.docs[0].first_product_name }} 




      &nbsp; 
      {% if groupResults.doclist.numFound > 4 %} 
      <a href="{{ path("design_picker_catalog", { "productSlug": groupResults.doclist.docs[0].first_product_slug, "search": searchTerm }) }}" style="float:right">Show all {{ groupResults.doclist.numFound }} results</a> 
      {% endif %} 
      </td> 
     </tr> 

     <tr> 
     {% set count = 0 %} 
     {% for template in groupResults.doclist.docs %} 
      <td> 
       <a href="{{ path("customer_design_editor", { "templateSlug": template.slug, "productSlug": template.product_slug[0] }) }}"> 
        <img src="{{ path("design_template_thumbnail_by_slug", { "slug": template.slug}) }}" alt="" /> 
       </a> 
      </td> 
      {% set count = count + 1 %} 
     {% endfor %} 
     {% if count < 4 %} 
     {% for i in count..3 %} 
      <td>&nbsp;</td> 
     {% endfor %} 
     {% endif %} 
    {% else %} 
    {% endif %}  
    {% endfor %} 

+0

您可以編輯您的文章,以使其更容易被理解?我真的不明白你想做什麼。 – cheesemacfly

+0

確保............ – Sid

回答

4

如何:

{% set totalCount = firstGroup|length + secondGroup|length %} 
+0

嘿感謝答覆,但它不是隻有兩個productGroup我有很多productGroup。你可以在我的代碼中看到這... – Sid

+0

設置爲你的總,然後爲每個組只需要調用{%集TOTALCOUNT = TOTALCOUNT +組|長度%}一個變量,然後你不必給每個組內循環。當然,計數/總數可以在twig(php) – ste

+0

之前完成,謝謝它的工作。 – Sid