Partial templates: read parameters from Params and argument dictionary

Hi,

I have a partial template that is reading the page params in this way:

In the partial:

{{- $param1 := .Params.param1 -}}
{{- $param2 := .Params.param2-}}
...

And I’m calling the partial template simply with: {{ partial "my-partial" . }}.

I would like now to extend the partial template functionality adding the option to pass the params either when calling it {{ partial "my-partial" (dict "param1" "value" ...) }} or reading the args from the page .Params.param1, .Params.param2, etc…

I’ve been trying with this approach using the default keyword:

From the partial:

{{- $param1 := default .Params.param1 .param1 -}}

But, it is not working when calling the partial without an argument dictionary because .param1 is not found in the scope.

What do you suggest?

Thanks

{{ if reflect.IsMap . }}
  {{ with .param1 }}
    {{ . }}
  {{ end }}
{{ else }}
  {{ with .Params.param1 }}
    {{ . }}
  {{ end }}
{{ end }}
1 Like

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