Debian Codegraph @

docs/content/en/functions/math/Counter.md

raw
1 ---
2 title: math.Counter
3 description: Returns a global counter value, incrementing it each time the function is called.
4 categories: []
5 keywords: []
6 params:
7 functions_and_methods:
8 aliases: []
9 returnType: uint64
10 signatures: [math.Counter]
11 ---
12
13 The counter is global for both monolingual and multilingual projects, and its initial value for each build is 1.
14
15 ```go-html-template {file="layouts/page.html"}
16 {{ warnf "page.html called %d times" math.Counter }}
17 ```
18
19 ```text
20 WARN page.html called 1 times
21 WARN page.html called 2 times
22 WARN page.html called 3 times
23 ```
24
25 Use this function to:
26
27 - Create unique warnings as shown above; the [`warnf`][] function suppresses duplicate messages
28 - Create unique target paths for the `resources.FromString` function where the target path is also the cache key
29
30 > [!NOTE]
31 > 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.
32
33 [`warnf`]: /functions/fmt/warnf/