How to make code from partial to work in shorcode?

Im trying to read recipe info (recipe_metadata.serving) from front matter:

amount = 2
unit = "people"

I’m having this working code in partial:

{{ $metadata := .Params.recipe_metadata }}
{{ $metadata.serving }}

And I want it to implement it in one of my shorcodes. I tried like this:

{{ $metadata := $.Page.Params.recipe_metadata }}
{{ $metadata.serving }}

The error I get in this case is:

executing "shortcodes/recipe.html" at <$metadata.serving>: can't evaluate field serving in type []map[string]interface {}

How should I modify this code so I can read complex data (tables, nested tables) from front matter in shortcodes?

Thank you in advance,

That shortcode should work fine, as-is.

The way you have it currently, {{ $metadata.serving }} returns a map, e.g. map[amount:2 unit:people]

If you wanted to display every key/value in the map, then you could do this:

{{ $metadata := $.Page.Params.recipe_metadata }}

{{ range $key, $value := $metadata.serving }}
  {{ $key }} = {{ $value }}
{{ end }}

See the TOML docs on Tables for additional ways to organize your front matter data (if you’re not satisfied with the current setup)

Thanks. I appreciate your help that lead me in the right direction. On the way I also realized that some of the recipes files had still old format of front matter, so hugo fell in some problems when some fields with the same variable name were numbers, and sometimes they were strings.