New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use integer variables from front matter .Params #551
Comments
Did you use toml as your front matter, didn't you? I tested toml decoding behavior with a following small code package main
import (
"fmt"
"os"
"github.com/BurntSushi/toml"
)
func main() {
tomlStr := `foo = 10`
var data map[string]interface{}
if _, err := toml.Decode(tomlStr, &data); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
fmt.Printf("%#v\n", data)
if data["foo"] != 10 {
fmt.Println("foo isn't int(10)")
}
if data["foo"] != int64(10) {
fmt.Println("foo isn't int64(10)")
}
} It shows 10 is If this is true, one of the workarounds is using YAML as the front matter. YAML library used in Hugo converts 10 to |
Thanks for that. I can confirm that it works when I use YAML front matter format. So would be great to support that consistently in the others as well! |
btw same issue seems to exist for .Site.Params defined within config.toml |
TOML and YAML handles integers differently, creating issues when using integer values from configuration or front matter in the First template function. This currently works in YAML (parses into int), but not in TOML (parses into int64). This commit modifies First so it accepts any int. Fixes gohugoio#551
I cooked a patch fro the First-function, but as there may be more cases (now and in the future), this should maybe be solved by getting the sources in line, either by changing the libraries (not realistic) or create an adapter of kind (should be possible). The template API have a limited usage scope, but the interface{} type API for simple integer types looks kind of ... not so pretty. |
I see the same issue when using the result of "len" as an arg in "gt"
where somelist is defined in a TOML front matter
it seems to work output-wise, but I see this error from hugo
|
@galaktor My guess your last sample is something different. As it works "output-wise" my best guess is that you have |
Cheers @bjornerik that was it. Hard to figure these out sometimes :-) |
TOML and YAML handles integers differently, creating issues when using integer values from configuration or front matter in the First template function. This currently works in YAML (parses into int), but not in TOML (parses into int64). This commit modifies First so it accepts any int. Fixes gohugoio#551
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
I'm relatively new to Hugo, so I could be doing something wrong...but here goes.
It seems like I cannot use numerical (i.e. integer) values from my front matter params. I wanted to set a number in there and use it as an argument for the "first" function i.e.
I couldn't debug this properly but from what I saw using some "printf debugging" via the template, the foo variable was a string and first didn't like that.
Any way to cast or use number variables?
Thanks
The text was updated successfully, but these errors were encountered: