I’m really hoping that you can help me.
I have a for loop
<ul>
{% for product in collection.products %}
<li>{{product}}</li>
{% endfor %}
</ul>
I would like to create unequal rows:
first row – 2 products
second: 4
third 3
fourth: 2
fifth: 4
…..
And have something like this:
I’m trying to do this 2 month already. Could you please help me?
3
Answers
So you want rows like
You can use that schema to create css classes like this
And then in your code:
Note that this will work for an arbitrary number of elements. The final html will look like this
This is an example of the result.
Note that I’ve switched to
min-width
(and addedflex: 1
) to stretch the last elements to the maximum possible width.Not sure if you can do it with plain
liquid
itself without any tricks, but using js and css you will have a bit more freedom:Just modify css a little to make it fit your needs.
UPD: I wrote this fiddle for tests purposes https://jsfiddle.net/4y8d1kvq/
filteredProductIndexes
. and than check weather it contains anindex
or not withfilteredProductIndexes.includes(index)
.filteredProductIndexes.includes(index)
this will retunrtrue
if index is there andfalse
if not..setHalf
, which has css offlex:1 0 calc(50% - 30px);
(it means two items before wraping).product
I have set css toflex:1 0 calc(33.33% - 30px);
(this means three items before wrapping).skipFilter(seq, pick, skip)
pick
is how many item we want to select andskip
is how many items we want to skip andseq
is an array of indexes.