Radical Design Course by Jack McDade

From the creator of Statamic

Learn how to make your websites standout and be remembered.

Taking your approach on designing things actually makes it fun, more natural, and overall easier.

— Dominik, Developer

Increment Tag

Each time an increment tag is parsed, an index is incremented by one and displayed.

Overview

Most loops already have an index variable that will display which iteration the loop is on. However, there are cases were you may need to start another counter, begin counting from a particular number, or increment by a step size other than 1. For those reasons, this tag exists.

{{ items }}
{{ increment }}
{{ /items }}
@foreach ($items as $item)
<s:increment />
 
-- or --
 
{{ Statamic::tag('increment') }}
@endforeach
0 1 2 3 4 5
Hot Tip!

A counter will only be incremented if its parsed. You can wrap it inside an if condition if you want it to be conditionally incremented.

Multiple Counters

You can have multiple counters going at once in your view by giving each a unique name as the second tag argument.

{{ items }}
{{ increment:again }}
{{ /items }}
@foreach ($items as $item)
<s:increment:again />
@endforeach

Customize the Counters

Customize the counts using the from and by parameters.

{{ items }}
{{ increment from="0" by="200" }}
{{ /items }}
@foreach ($items as $item)
<s:increment from="0" by-"200" />
@endforeach
0 200 400 600 800 100

Parameters

from

integer

The number to start incrementing from. Default: 0;

by

integer

The size to increment by. Default: 1.

Docs feedback

Submit improvements, related content, or suggestions through Github.

Betterify this page →