Cms: Contains modifier should support Collections

Created on 14 Jul 2020  路  7Comments  路  Source: statamic/cms

{{ if items | contains:sellable:false }}

WIth the given data, I would expect to get false returned.

Screenshot 2020-07-14 at 18 41 42

I am getting true instead.

A link to the docs:
https://statamic.dev/modifiers/contains

Environment

Statamic version: 3.0.0.-beta-37

PHP version: 7.4

not a bug

All 7 comments

The problem might be, that I am passing a collection.

What if you convert it to json and then check if it contains sellable, like this:

{{ if items | to_json | contains:sellable:false }}

Cool idea!

Not working though.

If it's a Laravel collection (Illuminate\Support\Collection) you're talking about, what about if you convert it to an array before passing to your view/tag? Then try the to_json thing.

That should work.

To keep a clean syntax, I will go with a custom modifier.

{{ unless items | sellable }}
   Some text           
{{ /unless }}

My modifier simply says:

return ! $value->contains('sellable', false);

That modifier should support collections. I'll change the subject for you.

Actually, this is more of a task for the where modifier. This will work:

{{ if items | where:sellable }}
Was this page helpful?
0 / 5 - 0 ratings