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

    I’m trying to work with a prebuilt snippet, and add another param to the it invoke. Having read other posts, i see that it is just a case of putting [[ mySnipper? &Param1=`1` &Param2=`2`]] etc.

    The invoke had a param already that was called pid that takes [*id*], and this shows up in the snippet, no problem. Any additional param that i add doesn;t show up within the snippet. Any ideas?

    I’ve got the param in single ticks, not single quotes, have tried using isset within the snipper, have tried just outputting it, all are a no go

    Tony
      • 3749
      • 24,544 Posts
      What version of MODX?
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 33968
        • 863 Posts
        Looks like Evo from your tags. Why don’t you post your snippet call and code so we can troubleshoot?

        [[mySnippet? &param1=`1` &param2=`2`]]

        The above is the same as declaring:
        <?php
        $param1 = 1;
        $param2 = 2;
        

        in your snippet code.
          • 13195
          • 5 Posts
          Hi Both,

          Thanks for the replies.

          The idea of this is that i will be able to put the snippet into several templates, and change the param on the template based on if i want a certain output to appear or not. So yes the code may look pointless in the example above. This is what i have at the moment:

          This is the call to the snippet:
          [[ userAccount? &pid=`[*id*]` &pid2=`[*id*]` &isRegistration=`1` ]]

          And this is the PHP code within the snippet:

          <?php

          $isReg = 0;
          if ($isRegistration != ’’) {
          $isReg = 1;
          }

          echo $isReg . ’
          ’;
          echo "isRegistration " . $isRegistration . ’
          ’;
          echo "pid " . $pid. ’
          ’;
          echo "pid2 " . $pid2 . ’
          ’;

          ?>

          As you can see i have three params, two of them coming from Modx generated variables and then one that is hardcoded that i will use in different ways on different templates. the first param pid is available within the snippet, but the pid2 and isRegistration aren’t coming through.

          Any ideas?

          Tony
            • 3749
            • 24,544 Posts
            I don’t see anything wrong with your code (though the $isReg variable seems redundant -- you could just use $isRegistration).

            Take out the space at the beginning of the snippet tag.

            Note that if the ID is 0, it won’t print.

            You are using Evolution, right?
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              In Evo, that snippet works just fine exactly as copy/pasted from your post.
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 36404
                • 307 Posts
                hi,

                just a word to say that, $isRegistration seeming to be a boolean (1/0), in order to set a default value for $isReg you could do
                $isReg = isset($isRegistration) ? $isRegistration : 0;


                now, as Bob Ray lets it understand, if you’re steady enough in your snippet calls, you’ll always have a $isRegistration param then why not use directly $isReg in the snippet call
                [[userAccount? &pid=`[*id*]` &pid2=`[*id*]` &isReg=`1`]] // or $isReg=`0`
                and no start space as Bob says
                this way you will not have to check any value and be able to manipulate $isReg in the snippet instead of two vars that have the same value

                Have swing
                  réfléchir avant d'agir