todrobbins
todrobbins

Reputation: 123

Can you use two where conditions in an assign Liquid tag?

Can you use two where conditions in an assign Liquid tag?

I'm getting this build error when trying to bundle exec jekyll serve --trace:

Liquid Exception: Liquid error (line 7): wrong number of arguments (given 4, expected 3) in party/democratic/index.md
             Error: Liquid error (line 7): wrong number of arguments (given 4, expected 3)

This is the Liquid tag in question:

{% assign people = site.data.people |  where: election_2020.office, 'U.S. President' and election_2020.party, 'Democratic' | sort: 'last_names' %}

I can't find documentation one way or the other whether you can have two where filters in an assign tag.

PS: here's a sample of the people.yml file:

-
  id: 'julian-castro'
  first_names: 'Julián'
  last_names: 'Castro'
  full_name: 'Julián Castro'
  image: '/images/people/julian-castro-wikipedia.jpg'
  gender: 'male'
  image: '/images/people/julian-castro-wikipedia.jpg'
  election_2020:
    office: 'U.S. President'
    address: 'P.O. Box 501'
    latitude: '29.430018'
    longitude: '-98.4987548'
    city: 'San Antonio'
    state: 'TX'
    zip: '78292'
    donate: 'https://secure.actblue.com/donate/julianforthefuture'
    facebook: 'https://www.facebook.com/julianforthefuture/'
    instagram: 'https://www.instagram.com/juliancastrotx/?hl=en'
    twitter: 'https://twitter.com/JulianCastro'
    website: 'https://www.julianforthefuture.com/'
    party: 'Democratic'
    election_type: 'primary'
    source: 'https://voteinfo.utah.gov/2020-presidential-candidates/'
    candidate_status: 'withdrew'
  last_updated: '2020-02-20'

Upvotes: 1

Views: 699

Answers (1)

David Jacquel
David Jacquel

Reputation: 52789

Where filter allows only to compare a key value with another value. If you want to use complex filtering you can use where_exp filter.

{% assign people = site.data.people | where_exp: "someone", "someone.election_2020.office == 'U.S. President' and someone.election_2020.party == 'Democratic'" | sort: "last_names" %}

Upvotes: 3

Related Questions