satis icon indicating copy to clipboard operation
satis copied to clipboard

Group by vendor in html.

Open artmouse opened this issue 4 years ago • 3 comments

Hello! How can I make foreach for vendors in HTML? I want to group by vendor. Thanks!

Vendor_1 (view/img/Vendor_1.jpg)------------Vendor_2 (view/img/Vendor_2.jpg)
|_ Vendor_1/Package_1, Latest_version--------|_ Vendor_2/Package_1, Latest_version |_ Vendor_1/Package_2, Latest_version--------|_ Vendor_2/Package_1, Latest_version |_ Vendor_1/Package_3, Latest_version--------|_ Vendor_2/Package_3, Latest_version |_ Vendor_1/Package_4, Latest_version--------|_ Vendor_2/Package_4, Latest_version

artmouse avatar Mar 05 '20 11:03 artmouse

It can be done entirely inside the template code. Inside foreach split the vendor. Compare with the previous loops vendor (empty string during the first loop). If it's different, create a new group header or whatever you need, otherwise continue the group.

You can provide your own template via config options.

The packages are already in alphabetical order, no extra processing necessary.

SvenRtbg avatar Mar 05 '20 11:03 SvenRtbg

I have already defined my new template. I can’t understand how to get all the packages inside the vendor. I find oly this: {% for name, package in packages %}{% include 'package.html.twig' %}{% endfor %}

artmouse avatar Mar 05 '20 11:03 artmouse

I'm only telling from memory, I'm not next to my machine.

Assuming that the included file outputs one package, you should probably detect the new vendor inside that loop before the include, or even add alternative or additional includes.

It all boils down to how (in HTML) you want to "group".

Just as an example: If it's the first loop, add "

", then include. If the vendor changes, add "
". If it's the last loop, close with "
" after the include.

SvenRtbg avatar Mar 05 '20 11:03 SvenRtbg