Skip to content
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

Conditional comparison where field is false causes build to fail and exit. #13207

Closed
skoblenick opened this issue Dec 30, 2024 · 3 comments
Closed

Comments

@skoblenick
Copy link
Contributor

skoblenick commented Dec 30, 2024

What version of Hugo are you using (hugo version)?

$ hugo version
hugo v0.140.2+extended+withdeploy darwin/amd64 BuildDate=2024-12-30T15:01:53Z VendorInfo=brew

The issue also existed in 1.4.0.

Does this issue reproduce with the latest release?

Yes.

Issue

Boolean Comparison in collection comparison causes the build/serve command to fail.

I have a data folder containing a structure like:

# ./data/en/features.yml
- name: feature 1
  paid: true
- name: feature 2
  paid: false

Within my theme I have a partial that contains:

      {{ $lang := .Site.Language.Lang }}
      {{ $data := index .Site.Data $lang }}
      {{ range $index, $feature := where $data.features "paid" false }}
        <li class="grid gap-4">
          <div class="flex flex-col gap-3 items-center align-middle">
            <img class="w-10" src="{{ $feature.icon }}" />
            <h4 class="text-md font-bold">
              {{ htmlUnescape $feature.title }}
            </h4>
          </div>
          <p class="">{{ htmlUnescape $feature.description }}</p>
        </li>
      {{ end }}

which causes a failure upon running hugo serve --bind=0.0.0.0 --watch:

Error: error building site: render: failed to render pages: render of "/" failed: "themes/my-theme/layouts/_default/home.html:10:7": execute of template failed: template: _default/home.html:10:7: executing "main" at <partial "features/core" .>: error calling partial: "/themes/my-theme/layouts/partials/features/core.html:31:46": execute of template failed: template: partials/features/core.html:31:46: executing "partials/features/core.html" at <$feature.title>: can't evaluate field title in type interface {}

However, the same data and template with the flag set to true works as expected. I have also attempted to use:

 {{ range $index, $feature := where $data.features "paid" "eq" false }}
 {{ range $index, $feature := where $data.features "paid" "ne" true }}

all with the same result. The only method that I have found works is:

 {{ range $index, $feature := where $data.features "paid" "eq" "false" }}

which is less than ideal, as it forces me to change the data types and use a string rather than a bool value for the paid and other bool type fields.

Additional notes:

It's a janky workaround and wouldn't work using build, but if I modify the partial to true on the launch of serve command, then modify the partial to false after the service is available, the template continues to compile and works as expected.

@jmooring
Copy link
Member

The where condition isn't the problem. This example uses your code (see layouts/_default/home.html) and your data:

git clone --single-branch -b hugo-github-issue-13207 https://github.com/jmooring/hugo-testing hugo-github-issue-13207
cd hugo-github-issue-13207
hugo server

Works great. You have a different problem.

Please create a new topic on the forum where we handle questions and troubleshooting. Thanks.

@skoblenick
Copy link
Contributor Author

Thanks for the example repo, it helped me identify the issue. It was being caused by a malformed structure in my fr data file; the english file was in the correctly structure.

Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 22, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy