I use this code to count the number of figures in my site and associate to each of them a number.
(I try to reproduce the same figure numbering than in LaTeX for example).
Currently, I have another shortcode used to make reference to this counter from other pages:
{{ with .Site.GetPage "/blog/page_with_fig.md" }}
Figure {{ .Page.Scratch.Get (.Get "key") }} <br>
Counter {{ .Page.Scratch.Get "nfig" }} <br>
end
{{ end }}
However, this code does not display the same thing depending on the pages:
Sometimes, I have:
Figure X (X depends on the “key”, 1 to 3)
Counter 3
And in another page, I have:
Figure
Counter
In the last case, the different variables seem to not exist depending on the caller page.
I supposed it comes from the order used to build the pages, but I am not sure of this hypothesis.
I think a solution can be to force Hugo to build two times the website to create the different variables before using them, but I am not sure if it is possible …
Any idea on this issue ?
Ideally I want a unique figure number per page.
However, if you have a working solution with a unique figure number for every figure on the site, it also interests me !
If in Page A I have (the parenthesis are not displayed):
Figure 1 (associated to key=“a”)
Figure 2 (associated to key=“b”)
Figure 3 (associated to key=“c”)
I want on Page B (and for any possible Page B) to be able to recover the value associated to each Figure using the corresponding key, to be able to do things like:
“In Figure (key=“a” ->) 1 of Page A, …”
“In Figure (key=“b” ->) 2 of Page A, …”
“In Figure (key=“c” ->) 3 of Page A, …”
Instead of my actual result which displays in some Page B:
“In Figure of Page A, …”
“In Figure of Page A, …”
“In Figure of Page A, …”
Let’s start with an example that auto-numbers the figures on each page using the shortcode .Ordinal property.
git clone --single-branch -b hugo-forum-topic-37903 https://github.com/jmooring/hugo-testing hugo-forum-topic-37903
cd hugo-forum-topic-37903
hugo server
Post 1 contains the figures.
Post 2 references the figures on Post 1.
Thanks for this suggestion: I didn’t know .Ordinal. I will read the documentation about it.
However, in your example, you are refering to the Figure directly by using their number:
[this figure on Post 1]({{< relref "posts/post-1#figure-1" >}})
In my case, I want to be able to dynamically recover this number only using a key…