math.Counter
Increments and returns a global counter.
Syntax
math.Counter
Returns
uint64
The counter is global for both monolingual and multilingual sites, and its initial value for each build is 1.
layouts/page.html
{{ warnf "page.html called %d times" math.Counter }}WARN page.html called 1 times
WARN page.html called 2 times
WARN page.html called 3 timesUse this function to:
- Create unique warnings as shown above; the
warnffunction suppresses duplicate messages - Create unique target paths for the
resources.FromStringfunction where the target path is also the cache key
Due to concurrency, the value returned in a given template for a given page will vary from one build to the next. You cannot use this function to assign a static id to each page.
Last updated:
July 7, 2025
:
Merge commit 'bb147f91ee9078e6a55e8c32ab4b2e5dbc5cee45' (079671b41)
Improve this page