Example 23: Counter Source

Counter Syntax

Increment: 🔂name

Increments the counter named name and substitutes the new value. Each occurrence adds one, so five blocks get 1, 2, 3, 4, 5.

Peek: 🔂_name

Reads the current value of counter name without incrementing. Use this when multiple tokens in one block need the same counter value — for example, 📊title🔂num increments (giving 📊title1), and 📊desc🔂_num peeks (giving 📊desc1, not 📊desc2).

Multiple Independent Counters

Each counter name is tracked independently. This page uses two: 🔂cat numbers the category headers, and 🔂num numbers the photo cards — they count separately. Here 🔂cat reaches 3 while 🔂num reaches 5; they never interfere with each other.

This page includes 🪪category-header blocks and 🪪photo-card blocks interleaved — three categories (cat 1→2→3) containing five photos (num 1→2→3→4→5).

Category 1: Landscapes

Sunset

Golden hour at the beach

Ocean

Pacific coast waves

Category 2: Nature

Forest

Misty morning in the woods

Mountain

Snow-capped peaks at dawn

Category 3: Terrain

Desert

Sand dunes at midday

How This Was Built

# blocks/category-header.html — uses 🔂cat
<header class="category-header">
  <h3>Category 🔂cat: 📊cat🔂_cat</h3>
</header>

# blocks/photo-card.html — uses 🔂num (independent from 🔂cat)
<article class="photo-card">
  <h2>📊title🔂num</h2>
  <p>📊desc🔂_num</p>
</article>

# data/gallery.toml
[_]
title1 = "Sunset"      desc1 = "Golden hour at the beach"
title2 = "Ocean"       desc2 = "Pacific coast waves"
title3 = "Forest"      desc3 = "Misty morning in the woods"
title4 = "Mountain"    desc4 = "Snow-capped peaks at dawn"
title5 = "Desert"      desc5 = "Sand dunes at midday"
cat1   = "Landscapes"
cat2   = "Nature"
cat3   = "Terrain"

The counter step runs once and handles all counter names — both 🔂cat and 🔂num are resolved by the same step, each tracking independently.