Conditionally show if collection has an odd number of entries? #6172
stephenmeehanuk
started this conversation in
General
Replies: 1 comment 1 reply
-
For this, I would recommend checking if the Regex or Runtime Antlers using modifiers: {{ collection:blog as="posts" }}
<ul>
{{ posts }}
<li class="{{ switch between='odd|even' }}">{{ title }}</li>
{{ /posts }}
{{# SHOW IF LAST ENTRY IS AN ODD NUMBER #}}
{{ if (total_results | %:2) != 0 }}
<li>Call to action</li>
{{ /if }}
</ul>
{{ /collection:blog }} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi
How would I conditionally show something if a collection has an odd number of entries?
I've added
{{ switch between='odd|even' }}
to the collection loop, this adds a class of odd or even.Can I use
switch
as part oflast
? I think I need something like, If last is odd then do this.Beta Was this translation helpful? Give feedback.
All reactions