Range over an index and print it's name

I’m using the following on my config.toml:

[params.profiles]
facebook = “https://facebook.com/brunoamaral
github = “https://github.com/brunoamaral
twitter = “https://twitter.com/brunoamaral

And my goal is to range over them, like so:

   	{{ range  (index $.Site.Params.profiles ) }}
   	<a href="{{ . }}" class="btn btn-primary btn-icon btn-round">
   	  <i class="fab fa-facebook"></i>
   	</a>
    {{ end }}

What is missing is getting this bit to be dynamic: class=“fab fa-facebook”>

How do I get the name of the parameter that is being displayed ?

You can range with a key and value: https://gohugo.io/templates/introduction/#example-4-declaring-variable-names-for-a-map-element-s-key-and-value

{{ range $key, $val := $map }}
1 Like

To create a key / value list a partial is a solution to define this list

Thank you @pointyfar! Here’s the working code in case someone needs it:

{{ $map := (index $.Site.Params.profiles ) }}
  {{ range $key, $val := $map }}
     <a href="{{ $val }}" class="btn btn-primary btn-icon btn-round">
	   <i class="fab fa-{{ printf $key }}"></i>
	</a>
{{ end }}