How can I print the param value name?


I have this in the front matter:

   fact_1: "This is the first fact."
   fact_2: "Second fact here."
   fact_3: "Third fact!"

And I’m doing:

{{ range sort .Params.facts "value" "desc" }}							
   <li>{{ . }}</li>
{{ end }}

So they print in reverse order (first one at the bottom)

I would like to add a <a href="#fact_1"> to each of the <li>, so I can anchor-link those in the content.

Do someone knows how can I print the param name? (fact_1, fact_2, fact_3, etc)? There’s .Param but it doesn’t appears to do what I want.

I can always manually add the anchor links in the Params and use | safeHTML to print them, but I was wondering if there was a more automatic way of doing it.

Have a look at this topic here: Range with an index counter
Probably something like:

{{ range $index, $element := sort .Params.facts "value" "desc" }}							
   <li><strong>{{ $index }}<strong> {{ $element }}</li>
{{ end }}
1 Like