HUGO

Cannot pass value to partial

i have a similiar problem:

data/contact_person.json

[
  {
    "name": "Smith",
    "marketing": "yes",
    "graphic": "no",
    "selling": "yes",
  },
  {
    "name": "Johnson",
    "marketing": "no",
    "graphic": "yes",
    "selling": "yes",
  },
]

contact.md

---
title: "contact"
slug: "contact"
contactPerson: "marketing"
---

single.html

{{ .Scratch.Set "department" .Params.contactPerson }}
{{ partial "contact_person" . }}

partial contact_person.html

{{ $contactDepartment := .Scratch.Get "department" }}
{{ $contactDepartment }} // = marketing WORKS! but not in the range argument. :(
{{ range where (where site.Data.contact_person "$contactDepartment" "yes") site.Language.Lang "de" }}
Name: {{ .name }}
{{ end }}

it ignores the var “$contactDepartment” totally.
if i put “marketing” instead of “$contactDepartment” in the range argument it works!

You need to provide a sample repo for people in this forum to see the full context of your project’s templates and why you’re unable to pass the value.

Also please have a look at this topic for future reference.

1 Like

Remove the quotes around $contactDepartment.

{{ range where (where site.Data.contact_person $contactDepartment "yes") site.Language.Lang "de" }}
1 Like