Site parameters availability in nested partials

I am really stumped.

I am callling a partial with:

{{ partial “semantic/jsonld/jsonld-person.html” (dict “context” . “person_id” .Params.id )}}

and within the partial "jsonld-person.html I have the following code:

{{ $context   := .context }}
{{ $person_id := .person_id }}
{{ $person := (index $context.Site.Data.person $person_id) }}
<script type="application/ld+json">
  {
    "@context": "http://schema.org"
    ,"@type": "Person"
    {{ with $person.email }},"email" : "{{ . }}"{{ end }}
    {{ with $person.image }},"image" : {{ partial "semantic/rdf/rdf-image.html" $person.image }}{{ end }}
  }
</script>

I am getting an error message telling me that $person_id in the index call is nil.

If I use a hard set string value, it works.
The output of {{ $person_id }} gives me a string value.

Any help or tips would be appreciated!

Randy

Hello @RandyKahle,

your script fails if .Params.id is not set in the front matter. Not set means it’s nil when accessed with the dot notation. Your script propagates with .Params.id -> "person_id" -> $person_id to the index function.

Looking for nil in a dict makes index fail. Therefore, you have to check if .Params.id is set. E.g. as follows:

{{ with .person_id }}
{{ $person := (index $context.Site.Data.person .) }}
// do something