Use a variable from the outer context within a "template"?

I want to use a variable from outside a template… in a different context within that template.

{{ $currLink := .URL }}

{{ range .Sections }}
    {{ template "docplate" . }}
{{ end }}

{{ define "docplate" }}
    {{ range .Pages }}
        {{ if eq .Permalink $currLink }}
            {{/* do something */}}
        {{ end }}
    {{ end }}
{{ end }}

Problem is, $currLink is unavailable in the template definition.

Scratch doesn’t seem to work either. Is there a way to “pass” that variable for usage inside the template?

Honestly, I have never used template; I just use partial … I believe they are the same?

In any case, you should be able to pass a dict to it instead of just the . (dot) – See the example here.

Thanks, dict ultimately did it. Wasn’t sure how to use it at first.

{{ template "docplate" (dict "cont" . "currUrl" $currUrl) }}

{{ define "docplate" }}
    {{ if and (isset . "currUrl") (isset . "cont") }}
        {{ $sameUrl := .currUrl }}
        {{ with .cont }}
            ...
            ...