We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18436
    • 135 Posts
    Hi Guys, with each day I’m getting more comfortable with MODX but a few things still pose an issue.

    Last night while trying to programme a snippet to execute another I ran into some problems and not having an internet connection at home can be quite frustrating ! Needless to say the db backup I put on my flashdrive was an old one, I tell you, way too many 2am sessions the last month.

    Anyway, what I’m struggling with is passing the parameters to the snippet to be executed. I’ve just done some tests and managed to call the PageTrail snippet successfully (it has no required parameters) using the following code in a snippet called "test":

    $snippetName = 'PageTrail';
    $modx->runSnippet($snippetName);
    $output = $modx->runSnippet($snippetName);
    echo $output;
    


    Now how would I go about passing parameters to a snippet like NewsListing?
    Also how do I pass a snippet variable as a string i.e. [[Snippetname?&message=’Got anything to say?’]]. The "?" gets stripped out of the variable.

    Any help would be greatly appreciated!
      • 32241
      • 1,495 Posts
      You can past an associative aray on the second parameter. It will automatically going to be parsed by the API.

      Never use it, but I believe it will work wink
        Wendy Novianto
        [font=Verdana]PT DJAMOER Technology Media
        [font=Verdana]Xituz Media
        • 18436
        • 135 Posts
        Thanks for the response, here’s the snippet code that now works correctly !

        $snippetName = 'PageTrail';
        $snParams = array();
        $snParams['sep'] = '|';
        $output = $modx->runSnippet($snippetName, $snParams);
        echo $output;
        
          • 32241
          • 1,495 Posts
          Cool, glad you got it working.
            Wendy Novianto
            [font=Verdana]PT DJAMOER Technology Media
            [font=Verdana]Xituz Media