Example 23: Counter Source

Basic Counter Demo

This page includes the photo-card block five times. After the block step expands each card, the counter step replaces each counter token with 1, 2, 3, 4, 5 in order. The data step then resolves the numbered title and description keys from data/gallery.toml.

The photo-card template uses a composite key — the data key prefix combined with the counter value. An “underscore peek” variant reads the current counter without incrementing, so both the title and description on the same card use the same number.

How This Was Built

# blocks/photo-card.html
<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"