satis
satis copied to clipboard
Group by vendor in html.
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
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.
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 %}
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 "