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” )}}

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": ""
    ,"@type": "Person"
    {{ with $ }},"email" : "{{ . }}"{{ end }}
    {{ with $person.image }},"image" : {{ partial "semantic/rdf/rdf-image.html" $person.image }}{{ end }}

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!


Hello @RandyKahle,

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

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

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