You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I pass the Example struct to the data for view.Execute then in the template I have something like
{{ if .SomeField == "some_value" }} HAS SOME VALUE {{ end }}
The expression will always be False because the type of ".SomeField" is a *string and the Right-hand side is string so they are considered incompatible.
The "solution" was to add a Global function like this
views.AddGlobalFunc("nz", func(a jet.Arguments) reflect.Value {
// Helps convert the *string fields to just a string we can compare.a.RequireNumOfArguments("nz", 1, 1)
val:=a.Get(0)
ifval.IsNil() {
returnreflect.ValueOf("")
}
result:=cast.ToString(val.Interface())
returnreflect.ValueOf(result)
})
And use this ie
{{ if nz(.SomeField) == "somevalue") }}
And it now works as expected because the function will make sure it's a String
I have just started working with Jet, so Apologies if I have missed something. Thanks for all your work.
The text was updated successfully, but these errors were encountered:
I have a Struct like this
If I pass the Example struct to the
data
forview.Execute
then in the template I have something likeThe expression will always be False because the type of ".SomeField" is a
*string
and the Right-hand side isstring
so they are considered incompatible.The "solution" was to add a Global function like this
And use this ie
And it now works as expected because the function will make sure it's a String
I have just started working with Jet, so Apologies if I have missed something. Thanks for all your work.
The text was updated successfully, but these errors were encountered: