mirror of
https://github.com/CaiJimmy/hugo-theme-stack.git
synced 2025-04-29 03:53:30 +08:00
If the `params` key is not defined in the config file, accessing `params` results in a `nil pointer evaluating interface {}` error because `params` does not exist. This can be fixed by ensuring that params is always a map.
16 lines
654 B
HTML
16 lines
654 B
HTML
{{- $scope := default "homepage" .Scope -}}
|
|
{{- $context := .Context -}}
|
|
{{- with (index .Context.Site.Params.widgets $scope) -}}
|
|
<aside class="sidebar right-sidebar sticky">
|
|
{{ range $widget := . }}
|
|
{{ if templates.Exists (printf "partials/widget/%s.html" .type) }}
|
|
<!-- Ensure that the params always exist -->
|
|
{{- $params := .params | default (dict) -}}
|
|
|
|
{{ partial (printf "widget/%s" .type) (dict "Context" $context "Params" $params) }}
|
|
{{ else }}
|
|
{{ warnf "Widget %s not found" .type }}
|
|
{{ end }}
|
|
{{ end }}
|
|
</aside>
|
|
{{ end }} |