-
Notifications
You must be signed in to change notification settings - Fork 18k
text/template: Cannot compare slice to nil in template using eq or ne #51642
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
Comments
eq
to ne
note you can do cc @robpike |
@seankhliao Thanks for the suggestion, but what I want to achieve is to replicate PHP's isset() function. I want to check if the slice variable is set in the template if it's set render the result html; if it's empty, show "no results" string and display the results if there are any. If I use |
This is indeed a bug. The eq (and by extension ne) functions do not handle comparisons with nil. |
Change https://go.dev/cl/392274 mentions this issue: |
@robpike Hi, just wondering if the fix is included in 1.18? If not, when the fix will be landed? |
The fix for this will be in the future 1.19 release. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
https://go.dev/play/p/GOfZUGAcoI1
code:
What did you expect to see?
What did you see instead?
The text was updated successfully, but these errors were encountered: