Forum

Thread tagged as: Question

How do you output a counting variable?

Hi,

I have a question from a developer who I often collaborate with on website projects but is new Perch:

In Perch for a loop of posts, how do you output a counting variable?

For example

<div id="1"></div> <div id="2"></div>

//on an even count, put this div here

<div class="clear"></div>

So output would be

<div id="1"></div> <div id="2"></div> <div class="clear"></div> <div id="3"></div> <div id="4"></div> <div class="clear"></div> <div id="5"></div> <div id="6"></div> <div class="clear"></div>

I look forward to your comments

Neil Duddridge

Neil Duddridge 1 points

  • 6 years ago
Michael Wilkinson

Michael Wilkinson 6 points
Registered Developer

Hi Neil

It's all in the templates...

<perch:every count="2">
    <div class="clear">
</perch:every>

You can even do nth-child values like CSS.

Read it here: https://docs.grabaperch.com/docs/templates/conditionals/every

Thanks Michael - perfect :)