Context Changing unexpectidly in Partial

I am having difficulty when setting the context to a custom dict inside a partial.

First off, I have a shortcode in layouts/_shortcodes/map.html that is intended to add a leaflet map. The relevant part is below:

...

{{ $mapdetails := dict
    "points" (.Store.Get "points")
    "id" (printf "map_%d" .Ordinal)
}}

{{ partial "map.html" $mapDetails }}

For the purposes of testing, layouts/_partials/map.html just contains:

<pre>{{ debug.Dump . }}</pre>

As I would expect, this dumps the following:

{
  "id": "map_0",
  "points": [
    {
      "latitude": "48.{REDACTED}",
      "longitude": "2.{REDACTED}"
    }
  ]
}

However, if I attempt to access any of those elements (for example):

<h2> {{ .id }} </h2>
execute of template failed at <.id>: can’t evaluate field id in type *hugolib.ShortcodeWithPage

I am fairly new to hugo, so may be misunderstanding something. I am using Hugo v0.147.9

Turns out it was user error. That wasn’t the only place I was calling the map partial.

I’ll close this. Apologies for wasting your time

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.