If/else that checks if there's an odd or even amount of entries

Alright, I'm going to do my best to explain this.

A website I'm building (Statamic v2) has a collection and the fieldset for the homepage lets my client select which of the entries they'd like to display on the homepage.

Using Bootstrap, each entry is placed in a col-6, meaning it spans 50% of the content container. So the first entry would go left, the second right, the third left on the second row, the fourth right on the second row, and so on.

I've hard coded a col-6 at the end of this list, containing a button to show all entries.

Now for the interesting part: the items on the left (the odd numbered items) get a left-padding, while the items on the right (the even numbered items) get a right-padding.

That means that that hard coded last entry should get a left-padding when there's an even number of entries and a right-padding when there's an odd number of entries.

I hope this makes sense.

I could of course go with incredibly verbose and non-sustainable code like:

{{ if entries | count == '1' }}right-padding{{ elseif entries | count == '2' }}left-padding{{ elseif entries | count == '3' }}left-padding{{ elseif entries | count == '4' }}right-padding{{ /if }}

But I don't want to put a max_items on the field and I'm looking for a more elegant solution. So far, {{ if entries | count == 'odd' }} doesn't work — is there any way I can get this going?


>>>>>>> Unanswered <<<<<<<
7 Replies