Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Bug: without filter doesn't really filter out anything #3137

Closed
jan-dh opened this issue Jul 24, 2018 · 4 comments
Closed

Bug: without filter doesn't really filter out anything #3137

jan-dh opened this issue Jul 24, 2018 · 4 comments

Comments

@jan-dh
Copy link

jan-dh commented Jul 24, 2018

Description

When trying to get all the sites except for the current one, you should be able to filter it out like so:

{% set otherLocales = craft.app.sites.getAllSites()|without(currentSite.id) %}.

However, the |without filter doesn't filter out anything. This will still give you a list with all the current sites.

Steps to reproduce

  1. Create a Craft site with multiple sites
  2. Try filtering in the templates with {% set otherLocales = craft.app.sites.getAllSites()|without(currentSite.id) %}

Have tried it as such : {% set otherLocales = craft.app.sites.getAllSites()|without(currentSite) %} , but with the same result.

Additional info

  • Craft version: 3.0.16.1
@brandonkelly
Copy link
Member

brandonkelly commented Jul 24, 2018

craft.app.sites.getAllSites() will give you an array of craft\models\Site objects. currentSite.id is an integer. So it is expected that your |without doesn’t have any effect on the array; none of the values in it are the same as the integer you’re passing in.

If you drop the .id it should work, though.

{% set otherLocales = craft.app.sites.getAllSites()|without(currentSite) %}

@jan-dh
Copy link
Author

jan-dh commented Jul 24, 2018

Yes, I also tried it without the .id but that also doesn't seem to work. Still gives me all my three sites.
Issue is not really closed.

brandonkelly added a commit that referenced this issue Jul 24, 2018
@brandonkelly
Copy link
Member

Sorry, you’re right, |without was broken if you passed an object into it. Fixed for today’s release.

@jan-dh
Copy link
Author

jan-dh commented Jul 24, 2018

Thanks!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants