Error while accessing a headless leaf bundle in multilingual mode

I’m getting the following error:

execute of template failed: panic in Execute: runtime error: invalid memory address or nil pointer dereference. See "https://github.com/gohugoio/hugo/issues/5327" for the reason why we cannot provide a better error message for this.

I isolated the issue in a minimal project, adding the following files to an empty project:

content/bundle/index.md

---
headless: true
title: Bundle Title
---

layouts/index.html

{{- $bundle := .Site.GetPage "/bundle" -}}
{{- $bundle.Title -}}

config.toml

[languages]
  [languages.en]
  [languages.es]

If you empty the config.toml or replace index.md with index.es.md and index.en.md the error goes away.

Any thoughts on this?

Hey there,

do you have a repo for this minimal project?

I don’t. I thought creating a repo for this is overkill. You can create the project with this script:

hugo new site hugo-bundle-multilingual
cd hugo-bundle-multilingual
mkdir ./content/bundle
cat <<'EOF' >./content/bundle/index.md
---
headless: true
title: Bundle Title
---
EOF

cat <<'EOF' >./layouts/index.html
{{- $bundle := .Site.GetPage "/bundle" -}}
{{- $bundle.Title -}}
EOF

cat <<'EOF' >./config.toml
[languages]
  [languages.en]
  [languages.es]
EOF

Unrelated to the original topic, but I had to google what the heck cat <<'EOF' was doing. Very cool. TIL you can append multi-line strings to files like that :slightly_smiling_face:

1 Like

Since your bundle is only available in one of the sites, you need to do something ala:

{{ $bundle := .Site.GetPage "/bundle" }}
{{ with $bundle }}
{{ .Title }}
{{ end}}

Also note that you will get a better error message for this particular situation in the next Hugo.

2 Likes

I thought that all languages defaulted to this file. Is there way to achieve this? I have some images that are the same for every language and the index.md file exists to indicate that the folder is a headless bundle, not a content file per se, so it’s the same file for every language.

You need to duplicate the “index.md” file for every language; but the other languages will inherit the resources if not present

1 Like