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

simple OR/AND condition does not work #3685

Closed
lostika86 opened this issue May 11, 2021 · 9 comments · Fixed by #4257
Closed

simple OR/AND condition does not work #3685

lostika86 opened this issue May 11, 2021 · 9 comments · Fixed by #4257
Labels

Comments

@lostika86
Copy link

lostika86 commented May 11, 2021

Bug Description

There is a real need of checking more than one variable in conditions.
example: when we use multisite, and we check entry id, we have to check localized and origin id.

How to Reproduce

category:
  - 4734e652-c9f7-435d-aaf6-3c40abb7f040
  - 50fc0090-fa52-4d61-9365-040e5fae5a39

{{ category | raw | dump }}
image

{{ category | raw | in_array:90f61f30-8994-479a-a55b-e629db2bcc68 | dump }}
{{ category | raw | contains:90f61f30-8994-479a-a55b-e629db2bcc68 | dump }}
{{ category | raw | contains:4734e652-c9f7-435d-aaf6-3c40abb7f040 | dump }}
{{ category | raw | in_array:4734e652-c9f7-435d-aaf6-3c40abb7f040 | dump }}

image

{{ if category | raw | contains:90f61f30-8994-479a-a55b-e629db2bcc68 or category | raw | contains:4734e652-c9f7-435d-aaf6-3c40abb7f040 }}
// false
{{ if category | raw | in_array:90f61f30-8994-479a-a55b-e629db2bcc68 or category | raw | in_array:4734e652-c9f7-435d-aaf6-3c40abb7f040 }}
// false
{{ if category | raw | contains:50fc0090-fa52-4d61-9365-040e5fae5a39 and category | raw | contains:4734e652-c9f7-435d-aaf6-3c40abb7f040 }}
// false

Extra Detail

{{ if category | raw | contains:90f61f30-8994-479a-a55b-e629db2bcc68 or category | raw | contains:4734e652-c9f7-435d-aaf6-3c40abb7f040 }}
    <small>I need some trust ...</small>
    {{ else }}
    <small>Sry, no time for basics ... </small>
    {{ /if }}
    <br>
    <div>category | raw | in_array:90f61f30-8994-479a-a55b-e629db2bcc68 or category | raw | in_array:4734e652-c9f7-435d-aaf6-3c40abb7f040</div>
    {{ if category | raw | in_array:90f61f30-8994-479a-a55b-e629db2bcc68 or category | raw | in_array:4734e652-c9f7-435d-aaf6-3c40abb7f040 }}
    <small>I need some trust ...</small>
    {{ else }}
    <small>Sry, no time for basics ... </small>
    {{ /if }}
    <br>
    <div>category | raw | contains:50fc0090-fa52-4d61-9365-040e5fae5a39 and category | raw | contains:4734e652-c9f7-435d-aaf6-3c40abb7f040</div>
    {{ if category | raw | contains:50fc0090-fa52-4d61-9365-040e5fae5a39 and category | raw | contains:4734e652-c9f7-435d-aaf6-3c40abb7f040 }}
    <small>I need some trust ...</small>
    {{ else }}
    <small>Sry, no time for basics ... </small>
    {{ /if }}

dump is:
image

(looks like) same (old) issues: #2655, #3624

Environment

Statamic 3.1.11 Pro
Laravel 8.40.0
PHP 7.3.12
doublethreedigital/duplicator 1.3.1

Install method (choose one):

  • Fresh install from statamic/statamic
@JonKaric
Copy link
Contributor

Have you tried adding parenthesis? (https://statamic.dev/antlers#modifiers-inside-conditions)

@jackmcdade
Copy link
Member

@JonKaric has the answer right there — you need to group those sets of vars+modifiers with parenthesis and you should be good to go. Feel free to reopen if that doesn't do it!

@lostika86
Copy link
Author

Have you tried adding parenthesis? (https://statamic.dev/antlers#modifiers-inside-conditions)

I tried many variations, .. nothing helps.

@lostika86
Copy link
Author

@JonKaric has the answer right there — you need to group those sets of vars+modifiers with parenthesis and you should be good to go. Feel free to reopen if that doesn't do it!

I tried many variations, before I posted. Not every are posted here, but I tried to be descriptive to replicate issue.

These combinations does not work:

   {{ category | raw | contains:90f61f30-8994-479a-a55b-e629db2bcc68 | dump }}  // true

    {{ if (category | raw | contains:90f61f30-8994-479a-a55b-e629db2bcc68) or (category | raw | contains:4734e652-c9f7-435d-aaf6-3c40abb7f040) }}
    <p>I wanna see you, really ...</p>
    {{ /if }}

    {{ if ((category | raw | contains:90f61f30-8994-479a-a55b-e629db2bcc68) or (category | raw | contains:4734e652-c9f7-435d-aaf6-3c40abb7f040)) }}
    <p>I wanna see you, really ...</p>
    {{ /if }}

    {{ if (category | raw | contains:90f61f30-8994-479a-a55b-e629db2bcc68) OR (category | raw | contains:4734e652-c9f7-435d-aaf6-3c40abb7f040) }}
    <p>I wanna see you, really ...</p>
    {{ /if }}

    {{ if ((category | raw | contains:90f61f30-8994-479a-a55b-e629db2bcc68) OR (category | raw | contains:4734e652-c9f7-435d-aaf6-3c40abb7f040)) }}
    <p>I wanna see you, really ...</p>
    {{ /if }}

@JonKaric
Copy link
Contributor

@lostika86 Could you try this...

{{ if (category | raw | contains:90f61f30-8994-479a-a55b-e629db2bcc68) == true || (category | raw | contains:4734e652-c9f7-435d-aaf6-3c40abb7f040) == true }}

@lostika86
Copy link
Author

{{ if (category | raw | contains:90f61f30-8994-479a-a55b-e629db2bcc68) == true || (category | raw | contains:4734e652-c9f7-435d-aaf6-3c40abb7f040) == true }}

   {{ if (category | raw | contains:90f61f30-8994-479a-a55b-e629db2bcc68) == true || (category | raw | contains:4734e652-c9f7-435d-aaf6-3c40abb7f040) == true }}
        <p>Try .. </p>
    {{ /if }}

throws error
image

@lostika86
Copy link
Author

another with more parenthesis

    {{ if ((category | raw | contains:90f61f30-8994-479a-a55b-e629db2bcc68) == true) || ((category | raw | contains:4734e652-c9f7-435d-aaf6-3c40abb7f040) == true) }}
        <p>Try .. </p>
    {{ /if }}

image

@duncanmcclean duncanmcclean reopened this Jun 2, 2021
@jackmcdade
Copy link
Member

Just FYI, Antlers doesn't support nested parenthesis.

@lostika86
Copy link
Author

Nesting parenthesis was only a try, ... but good to know. Thank you

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

Successfully merging a pull request may close this issue.

4 participants