0

Hi can someone help me with the correct code for this statement because it is not working for me.

[[*id:isnot=`250` and isnot=`252`:then=`[[$qc-wrap]]`]]
mgonz
  • 45
  • 1
  • 8

3 Answers3

2

A more performant syntax would be:

[[[[*id:isnot=`250`:or:isnot=`252`:then=`$qc-wrap`:else=``]]]]

Note: updated to reflect comment below. Include a hyphen in the else value, as this:

[[[[ ... :else=`-`]]]]

Also note: an empty else condition can be left off entirely.

I think using or rather than and is appropriate here.

This article is great for understanding MODX conditionals:

https://sepiariver.com/modx/modx-output-filters-if-phx-conditional-statements-tutorial/

And this one for understanding the syntax above and why it's more performant:

https://modx.com/blog/2012/09/14/tags-as-the-result-or-how-conditionals-are-like-mosquitoes/

LIannotti
  • 382
  • 1
  • 11
  • 1
    This will trigger a warning/error, because the else-condition will result in a `[[]]`, and MODX will say "Didn't find Snippet". So better change your else to a `-`, so at the end it would be `[[-]]`, which is a valid MODX-comment. – Sebastian G. Marinescu Oct 05 '22 at 14:10
  • 1
    Thanks Sebastian. It's interesting, I've been using the empty backticks for years and never encountered an error. And the MODX forums as well as other SO answers have many examples of this same syntax as well. I will check to see if it's been generating warnings in my sites. – LIannotti Oct 05 '22 at 19:05
  • I'm thinking you probably never ran into the `:else`-case? Or maybe you have the system-setting `log_snippet_not_found` disabled? The exact error in the logs should be "could not find snippet with name". Any way, please let me know what your findings are. – Sebastian G. Marinescu Oct 07 '22 at 02:55
1

You use wrong syntax, please fix as follows:

[[*id:isnot='250':and:isnot='252':then='[[$qc-wrap]]']]

Don't forget to replace ' with ` within this example

Anton Tarasov
  • 534
  • 1
  • 7
  • 16
1

A simpler solution for this question is to use the :inarray output modifier to return an empty string, and use the :default output modifier to customize output for everything that doesn't match 250 or 252:

[[*id:inarray=`250,252`:then=``:default=`[[$qc-wrap]]`]]
CJHolowatyj
  • 349
  • 2
  • 11