Skip to content
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

Where filter always treats value as a string #3911

Closed
omgmog opened this issue Aug 13, 2015 · 3 comments · Fixed by #3935
Closed

Where filter always treats value as a string #3911

omgmog opened this issue Aug 13, 2015 · 3 comments · Fixed by #3935

Comments

@omgmog
Copy link

omgmog commented Aug 13, 2015

I noticed recently that the where: filter treats the value option as a string, even if a boolean is used:

Example post frontmatter:

---
title: foo
featured: true

---

Example usage of where: filter:

{% assign featured_posts = ( site.posts | where: "featured", true ) %}

>> featured_posts is empty

The same result is seen if we wrap true in quotes on the where: filter:

{% assign featured_posts = ( site.posts | where: "featured", "true" ) %}

>> featured_posts is empty

To make this work I had to wrap the true in quotes in both cases:

---
title: foo
featured: "true"

---
{% assign featured_posts = ( site.posts | where: "featured", "true" ) %}

>> featured_posts contains foo
@parkr
Copy link
Member

parkr commented Aug 14, 2015

yeah, the input to that where filter is always a string. We should do a .to_s when looking at the value to check against

@pathawks
Copy link
Member

This would be really useful in, for example, jekyll-sitemap, where we currently need an additional conditional in every loop. Being able to use the where filter would be much nicer, I think.

parkr added a commit that referenced this issue Aug 26, 2015
…rator

Non-string input was being missed as a result of poor comparison.
Converting inputs to strings ensure numerical and boolean values are
properly compared.

Fixes #3911.
@parkr parkr added the Bug label Aug 26, 2015
@omgmog
Copy link
Author

omgmog commented Aug 26, 2015

👏

@jekyll jekyll locked and limited conversation to collaborators Feb 27, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants