Construct a partial call with Data


I’m trying to make a call from within a TOML file data, like so:

current = "peter"

img = "/avatar.jpg"
      img = "btn.jpg"
img = "/avatar.jpg"
      img = "btn.jpg"

What I want is to change the value of current manually for anything I want, so when I call:

{{ .Site.Data.users.featured.current.btn }}

It displays the button info for rose, or peter, or anyone.

Problem is, as you might have guessed, that it shows me “peter” instead of the map.

My idea is to change current = “peter” and that the changes occur everywhere instead of manually changing all those calls.

{{ .Site.Data.users.featured.$current.btn }}

Doesn’t appears to work either, I can’t mix that into a variable.

Any ideas?

Use the index function.

Example from my theme: TOML data | template using index

Tweak in the template to make clear what’s happening:

(index $.Site.Data.svg "mastodon")

That "mastodon" string could have been "mastodon-alt" too, based on the value of (.svg | default (.name | lower)) in the template.

thanks for that, kaushalmodi, I was struggling really hard with it. You showed me the path.

Have a cookie >

Thanks! :smile:

1 Like