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

    I ran into a snippet parameter problem:

    The snippet call is the following:
    [!ifNotEmpty? &tv=`case_credits` &str=`<tr><td class="label">Créditos</td><td>[+ifnotempty+]</td></tr>` !]


    THE PROBLEM:
    Inside the snippet $str = "<tr><td clas" shocked huh

    Anyone has a clue of what’s happening?

    For info:
    I created the snippet ifNotEmpty that test if a tv is empty and if not insert it in a predefined html code (or a chunk using &tpl or a string using &str parameter) in the placeholder called [+ifnotempty+]. I want to keep the &str option else I’ll have to do a lot of chunks for every tv display.


    THANXXX

      • 10487 MODX Staff
      • 1,535 Posts
      You can’t have ’=’ signs in Evo snippet parameters. The parser cannot handle them (same for ’&’ and ’?’)

      You will have to try and use substitution values, for example, |eq| for ’=’, and go from there. Once the value has been passed to the snippet code, you can do a str_replace() to reverse the substitution.
        Garry Nutting
        Senior Developer
        MODX, LLC

        Email: [email protected]
        Twitter: @garryn
        Web: modx.com
        • 29861
        • 59 Posts
        Thanks for the answer.
        This should be writen in the docs like this one: http://wiki.modxcms.com/index.php/Snippet_call_anatomy
        I’m surely not the only one facing this problem.

        But I’m glad now, I can go on doing the str_replace thing wink

        Thanks again.
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          You can also code your snippet to take an external config file,
          [!ifNotEmpty?config=`assets/snippets/notempty/config.php`!]

          which is a simple .php file with a list of variable settings.
          <?php
          // parameters for ifNotEmpty snippet
          $tv = 'case_credits';
          $str = '<tr><td class="label">Créditos</td><td>[+ifnotempty+]</td></tr>';

          Or you can wrap your snippet in a wrapper snippet, define an array of parameters, then call the runSnippet API function.
          $params = array('tv'=>'case_credits','str'=>'<tr><td class="label">Créditos</td><td>[+ifnotempty+]</td></tr>');
          $output = $modx->runSnippet('ifNotEmpty', $params);
          return $output;
            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
            • 29861
            • 59 Posts
            Good to know those other possibilities but a chunk is another solution too. I’ll stick with the str_replace() because I have to use ifNotEmpty snippet several times.