Skip to content

Conversation

@bep
Copy link
Member

@bep bep commented Mar 11, 2016

@moorereason is this how "the others" are treating boolean in their defaults?

The test is deliberately failing.

@moorereason is this how "the others" are treating boolean in their defaults?
@moorereason
Copy link
Contributor

You bring up a good point about handling booleans in default. I almost decided to just return the given value if it was a bool because it just doesn't make a lot of sense to use default with a bool. For example,

{{ .Params.mybool | default true }} returns true every time.  Seems pointless.

I can't think of a good use case of using booleans with default.

Regarding other implementations:

  • Django: Same as Hugo; returns the default value if given is false. However, Django also has a default_if_none filter that returns the default only if the given value is None (undefined in Python).
  • Jinja2 is the opposite of Django. It tests for undefined values by default but can test for boolean if you tell it to.
@spf13
Copy link
Contributor

spf13 commented Mar 15, 2016

I'm not familiar with the "default" implementation. I think in this case that the default should only happen if the prior value is Nil, not set, or otherwise generates an Error (as in type mismatch) as both "true" and "false" are valid values.

@moorereason
Copy link
Contributor

I would propose that we accept all bool types as valid values and never use the default value.

@moorereason
Copy link
Contributor

I've submitted PR #1983 that should fix this issue. Please review.

@bep
Copy link
Member Author

bep commented Mar 16, 2016

Fixed in #1983

@bep bep closed this Mar 16, 2016
@rdwatters
Copy link
Contributor

FWIW, default implementation is same as Hugo (i.e., defer to default only when first value is undefined, false, or length === 0/nil) in Swig(JS), which makes me think we can assume it is the same in Twig (php, Drupal, Craft CMS).

Sent from my iPhone

On Mar 16, 2016, at 2:07 PM, Bjørn Erik Pedersen notifications@github.com wrote:

Closed #1953.


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub

@bep bep deleted the truth branch April 18, 2017 09:19
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

4 participants