hugo/docs/content/en/functions/math/Counter.md
Bjørn Erik Pedersen 5fd1e74903
Merge commit '9b0050e9aabe4be65c78ccf292a348f309d50ccd' as 'docs'
```
git subtree add --prefix=docs/ https://github.com/gohugoio/hugoDocs.git master --squash
```

Closes #11925
2024-01-27 10:48:57 +01:00

1 KiB

title description categories keywords action
math.Counter Increments and returns a global counter.
aliases related returnType signatures
uint64
math.Counter

The counter is global for both monolingual and multilingual sites, and its initial value for each build is 1.

{{ warnf "single.html called %d times" math.Counter }}
WARN  single.html called 1 times
WARN  single.html called 2 times
WARN  single.html called 3 times

Use this function to:

  • Create unique warnings as shown above; the warnf function suppresses duplicate messages
  • Create unique target paths for the resources.FromString function where the target path is also the cache key

{{% note %}} 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. {{% /note %}}