Hello.
I’m having a very strange error with data types.
At my company we are trying to make pages with partials (blocks for us).
This is our front matter page1.md, where we define inside [[blocks]]
some variables and configuration. Also we define [blocks.navbar]
that include another partial inside the first one.
title = "Design"
type = "page"
[[blocks]]
description = ""
template = "hero"
[blocks.navbar]
"class" = "is-transparent"
Then we have blocks.html
that has a Range function that include every partial defined inside [[blocks]]
in the frontmatter, into the specific page and pass throught context the variables defined inside [[blocks]]
{{ $site := .Site }}
{{- range .Params.blocks -}}
{{ $context := (dict "Site" $site "Block" .) }}
{{ $block_url := print (delimit (slice "blocks/" .template ) "") }}
{{ partial $block_url $context }}
{{- end -}}
The problem comes when I try to acess .Params.blocks.navbar.class
. If inside the Range function I add this line {{ printf "%#v" .navbar.class}}
then the build fail with this error.
executing "partials/blocks.html" at <.navbar.class>: can't evaluate field class in type interface {}
At that point, inside the Range function, the data type of .Params.blocks.navbar
is map[string]interface {}{"class":"is-transparent"}
. Idk why i can’t access class value, with .class
notation.
The crazy part comes when I try to imitate the map[string] interface, building a custom variable, with the following code and then try to print the content…
{{ $navbar_config := (dict "class" "is-transparent") }}
{{ printf "%#v" $navbar_config}}
I got the same data type as shown before, map[string]interface {}{"class":"is-transparent"}
but I can access the class field with no error
{{ printf "%#v" $navbar_config.class}}
result in “is-transparent”.
I’ve search the forum and the issues, but find nothing that helps me solve the problem. Idk if this is part of Hugo or is something weird happening in Go.
FYI: this is my env.
Hugo Static Site Generator v0.49.2/extended linux/amd64 BuildDate: unknown
GOOS="linux"
GOARCH="amd64"
GOVERSION="go1.11.1