We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14730
    • 34 Posts
    I want to filter TV’s by price.

    For instance, everything that costs more than $100:
    &tvFilters=`price>100`


    Or even a price range: equal or between $125 and $175:
    &tvFilters=`price>=125,price<=175`


    Unfortunately, this doesn’t work. Any suggestions for workarounds?
    Thanks!
      • 7557
      • 61 Posts
      Quote from: Jorik at Sep 22, 2010, 11:13 PM

      I want to filter TV’s by price.

      For instance, everything that costs more than $100:
      &tvFilters=`price>100`


      Or even a price range: equal or between $125 and $175:
      &tvFilters=`price>=125,price<=175`


      Unfortunately, this doesn’t work. Any suggestions for workarounds?
      Thanks!
      Hi,
      I do not know if there is a better way, but here are minimum two ways that you can solve it. The first way is with IF snippet. Let’s say you getResource chunk is simple:
      <a href="product">MyProduct price:[[+price]]</a>

      You can use IF nested snippet in your chunk like this:
      [[!If? &subject=`[[+price]]` &operator=`>=` &operand=`125` &then=`
      
      	[[!If? &subject=`[[+price]]` &operator=`<=` &operand=`175` &then=`
      
      		<a href="product">MyProduct price:[[+price]]</a>
      
      	`]]
      
      `]]


      Secound way may be less complicated for review, if You are using custom snippet. Create new snippet call it ifEval:
      <?php
        $return = false;
        $ifeval_str = '';
        $ifeval_str = 'if('.$input.') return true; else return false;';
        $return = eval($ifeval_str);
        if($return) return $content;


      And then if your getResource chunk:
      [[!ifEval? &input=`[[+price]]>=125 or [[+price]]<=175` &content=`<a href="product">MyProduct price:[[+price]]</a>`]]


      In the input parameter, You can use any of the signs of comparison (and other operators) and code that is used inside the ’IF’ function in PHP.
        • 7557
        • 61 Posts
        Slightly improved snippet:

        <?php
        /**
         * ifEval
         *
         * Simple functions for comparison and other operations. Use the correct php code, as the expression in the 'IF' function in PHP
         *
         * @ author Djordje Dimitrijev (dj13 on Modx forum)
         * @ version 0.1
         *
         * 3 parameters: input, contentFalse, contentTrue
         *
         * EXAMPLES:
         *
         * In template with contentTrue and contentFalse parameter
         * [[!ifEval? &input=`stripos("[[*pagetitle]]", "a")===0` &contentTrue=`<h3>Article with first letter A</h3>` &contentFalse=`<h3>Article with first letter different from A</h3>`]]
         * In chunk without contentFalse
         * [[!ifEval? &input=`[[+price]]>=125 or [[+price]]<=175` &contentTrue=`<a href="product.html">MyProduct price:[[+price]]</a>`]]
         *
         */
          
          $return = false;
          if(!$input) return false;
          if(!isset($contentFalse)) $contentFalse = false;
          if(!isset($contentTrue)) $contentTrue = false;
          $ifeval_str = '';
          $ifeval_str = 'if('.$input.') return true; else return false;';
          $return = eval($ifeval_str);
          if($return) return $contentTrue; else return $contentFalse;
          • 8168
          • 1,118 Posts
          Hi Dj13 - your solution here looks like it might be able to solve my quandary also! I have started a thread here on this - http://modxcms.com/forums/index.php/topic,55671.msg320261.html#msg320261 Any chance you could have a look and let me know if something like the solution you suggest here could work for me?


          Cheers,

          dubbs.