We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10313
    • 375 Posts
    Hello,

    I need a conditional operator "contains" to use something like this:
    [+mytv:conatins=`active`:then=`my output`+]

    Is this possible somehow?

    Martin
      • 16278
      • 928 Posts
      You could achieve this with a custom modifier and PHP strstr() function (or stristr for case-insensitive test). Create a snippet called phx:contains (or phx:conatins if you prefer tongue )
      <?php
      // phx:contains
      // return second option if first option exists in placeholder
      // placeholder value is in $output, test and return string if true in $options
      
      $input = explode(',',$options);
      $test = $input[0];
      $present = $input[1];
      
      $result = "not there!"; // or empty string, or $output, as required
      
      if (stristr($output,$test) !== false) {
        $result = $present;
      }
      
      return $result;
      ?>
      Call it like this: [+mytv:contains=`active,my output`+]
      laugh KP
        • 10313
        • 375 Posts
        Oh cool, Thank you!

        Nice joke, btw :-D