-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
tpl: adds truth
and bool
template functions
#10666
base: master
Are you sure you want to change the base?
tpl: adds truth
and bool
template functions
#10666
Conversation
For |
@khayyamsaleem thanks for this. My 50 cents about this, and please don't adjust your code before we agree on something is. As to {{ if "foo" }}OK{{ else }}Failed{{ end }}
{{ if ("foo" | truth) }}OK{{ else }}Failed{{ end }}
{{ if ("foo" | not | not ) }}OK{{ else }}Failed{{ end }} Which means that if would be a thin wrapper around As to //cc @jmooring |
A colleague of mine told me about a 700+ line YAML file they had to debug a few years ago. It had some country codes. Norway was falsy. |
@bep I'm fine with the suggestions; better to have one definition of truthiness for the codebase. |
@khayyamsaleem OK, if you adjust this PR to that much simpler scenario, I will merge. To be clear:
|
OK, I changed my mind again. Looking at the other cast.* functions we have, and also on other places we do similar, I think it's a pretty clear precedence to just use |
HI @bep. Does this PR needs more work? As far as I understood |
@bep pardon the delay here. Updated PR per your last review. |
The behavior of `truth` and `bool` is described in the corresponding test cases and examples. The decision-making around the behavior is a based on combination of the existing behavior of strconv.ParseBool in go and the MDN definition of "truthy" as JavaScript has the most interop with the Hugo ecosystem. Addresses gohugoio#9160 and (indirectly) gohugoio#5792
c38fbe1
to
858c07a
Compare
This is not what we agreed to:
|
Ahhh pardon, you're right. It did seem awkward for Truth and bool to disagree on "false" though. |
a93a70e
to
496ae98
Compare
Concession from review, where cast.ToTruth should behave exactly like hreflect.IsTruthful. Additionally, cast.ToBool always returns a bool with nil error.
496ae98
to
2843423
Compare
@bep I have not tested this yet, but I think the
and
Of course, that also raises the question, do we want a |
Are we waiting for @bep 's feedback here, or would we prefer to move the function to the |
The behavior of
truth
andbool
is described in the corresponding test cases and examples. The decision-making around the behavior is a based on combination of the existing behavior of strconv.ParseBool in go and the MDN definition of "truthy" as JavaScript has the most interop with the Hugo ecosystem.Fixes #9160 and (indirectly) #5792