Closed marcelloh closed 10 months ago
It's difficult to help you without seeing your template and data, but in general, make sure you're accessing your context using a .
.
For example, if you pass e.g. a map[string]any{"foo": "bar"}
as data
, you would write {{ .foo }}
to get bar
into the output.
data = map[string]any inside it: countrySelector with a value of: interface {}([]datamodels.Country) [{ID: 1, Name: "Afghanistan", Code: "AFG", Region: "Asia", SubRegion: "Southern Asia"},*{ID: 2, Name: "Åland Islands", Code: "ALA", Region: "Europe", SubRegion: "Northern Europe"},+186 more] This is part of my template
{{ if field.Name() == "Country"}}
{{ style = "width: 380px !important" }}
{{ filter := .record["Country"] }}
{{ field := "country" }}
{{ collection = countrySelector}}
{{ hasEmpty = "N" }}
{{ include "common/selector.jet" }}
{{ else if field.Name() == "NativeLanguage"}}
{{ filter := .record["NativeLanguage"] }}
{{ field := "nativelanguage" }}
{{ collection = languageSelector}}
{{ hasEmpty = "N" }}
{{ include "common/selector.jet" }}
{{ else }}
{{ field.Name() }} is not handled yet (in edit template)
{{end}}
This all worked in the master branch (without v6)
I have no clue where you expect countrySelector
in {{ collection = countrySelector}}
to come from. If you access it like this, and don't declare and/or set it earlier, it would have to come from the VarMap. If it's in the context (data
in the Execute() call), you would have to access it as .countrySelector
.
Do you mean the code worked with v2? jet uses Go modules since its v3 release. The master branch is the v6.2.0 code.
I've changed from 2 to v6 and I was using . countrySelector
, which should come from data.
I investigated this a bit more.
it seems that the error I've got when using . countrySelector
is complaining about the fact that it isn't initialised.
(So from v2 to v6 this has changed somehow)
I've changed all the parts into :=
{{ style = "width: 380px !important" }}
{{ filter := .record["Country"] }}
{{ field := "country" }}
{{ collection := countrySelector}}
{{ hasEmpty := "N" }}
{{ include "common/selector.jet" }}
and now everything works again. Thanks for your patience.
When I call this:
I have an issue with this:
Because I get an error: identifier "countrySelector" not available in current (map[field:country filter:NLD]) or parent scope, global, or default variables I know the data is filled with many parts, and countrySelector is one of them. For what I see is that resolve don't use the data which was put into st.context
Should I make data nil and put everything in variables (in the VarMap) ? (then why data exists?)