We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 11413
    • 203 Posts
    I would really need to get the params of my snippet in an array. I want to use all the params starting with a defined prefix to create a dynamic placeholder system in my code.

    I tried to use foreach with $_POST... but it don’t work. Maybe it’s my regex syntax that is wrong : i always had troubles with it. Anyway, some help would be appreciated here!

    Thanks,

    Blaise
      Blaise Bernier

      www.medialdesign.com - Solutions for small business, hosting, design and more!
      • 19667
      • 26 Posts
      Hi grunt_lord,

      I’m not sure if this solves your problem. But I give it a shot.

      FunctionCall
      [!funccall? &k1=`v1` &k2=`v2` &k3=`v3`!]


      Snippet [!funccall!]

      <?php
      var_dump (func_get_args());
      ?>


      Output
      array(2) { [0]=>  string(31) " var_dump (func_get_args()); " [1]=>  array(3) { ["k1"]=>  string(2) "v1" ["k2"]=>  string(2) "v2" ["k3"]=>  string(2) "v3" } }
      
      
        • 11413
        • 203 Posts
        Gonna try this right away! Thanks a lot!
          Blaise Bernier

          www.medialdesign.com - Solutions for small business, hosting, design and more!
          • 30223
          • 1,010 Posts
          Try
          $params = $modx->event->params 

          in your snippet.
            • 19667
            • 26 Posts
            Thats much smarter, indeed. wink
              • 11413
              • 203 Posts
              Damn! So simple! BTW, with func_get_args() you should do :

              $params = func_get_args();
              foreach ($params[1] as $name => $value) {
                 echo '$' . $name . ' == '  . $value;
              }
              


                Blaise Bernier

                www.medialdesign.com - Solutions for small business, hosting, design and more!