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

Add option to use AND rather than OR for multi-item collections #1605

Open
Ketrel opened this issue Aug 10, 2017 · 4 comments
Open

Add option to use AND rather than OR for multi-item collections #1605

Ketrel opened this issue Aug 10, 2017 · 4 comments

Comments

@Ketrel
Copy link

Ketrel commented Aug 10, 2017

The example in the docs show something like this
content: items: - '@self.children' - '@taxonomy': category: [blog, featured]

It goes on to explain (and in practice I also can confirm) that the behavior is it will show all children from the current page, as well as anything in the blog or featured category.

I'm trying to find a way to do something similar, but show things that match both rather than either, so it would have to be @self.children AND category: [blog,featured].

I can't find any way to do this with the current implementation.

@rhukster
Copy link
Member

rhukster commented Aug 11, 2017

We plan on implement a much more powerful query language in a future version of Grav to get around limitations in how collections are built. In the meantime, a workaround could be to use two collection defintions, and then merge them:

collection1:
   items: '@self.children'
collection2:
  items:
    - '@taxonomy':
         category: [blog, featured]

Then you merge them:

{% set collection1 = page.collection('collection1') %}
{% set collection2 = page.collection('collection2') %}
{% set collection = collection1.merge(collection2) %}

This will effectively combine the two collections creating an "OR" condition.

@Ketrel
Copy link
Author

Ketrel commented Aug 11, 2017

That's the exact opposite of what I'm asking.

It already does OR if you define multiple items

I'm asking about an AND condition.

@rhukster
Copy link
Member

Sorry misread your original issue. This turns out to be a little more complicated and requires some additional logic in Grav (namely a new Collection::intersect() method that can intersect multiple collections. I've added this and its ready for testing in the develop branch.

@rhukster
Copy link
Member

Example:

{% set collection1 = page.collection('collection1') %}
{% set collection2 = page.collection('collection2') %}
{% set collection = collection1.intersect(collection2) %}

OleVik added a commit to OleVik/grav-learn that referenced this issue Jul 15, 2018
- [x] Document optional collection ordering PHP flags getgrav/grav#1640
	- Added under /content/collections#php-collections
- [x] Added cache_control system and page override getgrav/grav#1591
	- Added reference-link to /basics/grav-configuration#pages
	- Added /content/headers#cache-control
- [x] clear_images_by_default cache option getgrav/grav#1481
	- Clarified description in /basics/grav-configuration#pages
- [x] Collection::intersect() getgrav/grav#1605
	- Added under /content/collections#collection-object-methods
- [x] Collection::merge() method
	- Added under /content/collections#collection-object-methods
- [x] Page::collection() filtering
	- Added under /content/collections#complex-collections, with a bit of cleanup
- [x] Document EXIF support in Grav (and in capabilities)
	- Clarified /themes/twig-filters-functions#exif
	- Added note at the end of /cookbook/general-recipes#creating-a-simple-gallery
- [x] document not being able to scroll caused by cloudlare. getgrav/grav-plugin-admin#808 (comment)
	- Done in getgrav#397
	- Duplicated under Admin Plugin and Cookbook headers
- [x] Document adding custom form fields with examples..
	- Done in getgrav#401
- [x] Document range field
	- Done in [7e0dcbc](getgrav@7e0dcbc)
- [x] Tutorial on how to create a split menu system (vertical menu?)
	- Duplicated under Cookbook header
- [x] Tutorial walkthrough covering going from and HTML site/design to Grav theme
	- Duplicated under Cookbook header

getgrav#356 needs some cleanup to remove completed tasks, they're not really needed.
rhukster pushed a commit to getgrav/grav-learn that referenced this issue Jul 27, 2018
- [x] Document optional collection ordering PHP flags getgrav/grav#1640
	- Added under /content/collections#php-collections
- [x] Added cache_control system and page override getgrav/grav#1591
	- Added reference-link to /basics/grav-configuration#pages
	- Added /content/headers#cache-control
- [x] clear_images_by_default cache option getgrav/grav#1481
	- Clarified description in /basics/grav-configuration#pages
- [x] Collection::intersect() getgrav/grav#1605
	- Added under /content/collections#collection-object-methods
- [x] Collection::merge() method
	- Added under /content/collections#collection-object-methods
- [x] Page::collection() filtering
	- Added under /content/collections#complex-collections, with a bit of cleanup
- [x] Document EXIF support in Grav (and in capabilities)
	- Clarified /themes/twig-filters-functions#exif
	- Added note at the end of /cookbook/general-recipes#creating-a-simple-gallery
- [x] document not being able to scroll caused by cloudlare. getgrav/grav-plugin-admin#808 (comment)
	- Done in #397
	- Duplicated under Admin Plugin and Cookbook headers
- [x] Document adding custom form fields with examples..
	- Done in #401
- [x] Document range field
	- Done in [7e0dcbc](7e0dcbc)
- [x] Tutorial on how to create a split menu system (vertical menu?)
	- Duplicated under Cookbook header
- [x] Tutorial walkthrough covering going from and HTML site/design to Grav theme
	- Duplicated under Cookbook header

#356 needs some cleanup to remove completed tasks, they're not really needed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants