We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37909
    • 153 Posts
    My snippet call:
    [[!transform? &var=`[[+total]]`]]


    My snippet:
    $total = var_dump($var);
    return $total;


    The result:
    string(18) "3"


    So, I change my snippet to this:
    $var = (int) $var;
    $total = var_dump($var);
    return $total;


    The result:
    int(0)


    I change the snippet
    $var = $var+0;
    $total = var_dump($var);
    return $total;


    The result:
    int(0)


    What the hell? HEEEELLLPPP!!!!
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      In the first place, you should use getOption to deal with properties.
      $var = $modx->getOption('var', $scriptProperties);


      Var_dump has no return value to assign to a variable. It dumps directly to screen.

      $var = $modx->getOption('var', $scriptProperties, 0);
      return (int)$var;


      What is it you are trying to do?
        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
        • 37909
        • 153 Posts
        I use var_dump just to see what's happened to $var

        I change my code:
        $var = $modx->getOption('var', $scriptProperties, 0);
        $total = (int)$var;


        If I return $var
        3


        If I return $total
        0


        ??
          • 3749
          • 24,544 Posts
          'var' is a reserved word in PHP. Possibly that's the problem.
            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
            • 37909
            • 153 Posts
            $nb = $modx->getOption('nb', $scriptProperties, 0);
            $total = (int)$nb;


            If I return $nb, I have 3, but 0 if I return $total

            It's difficult to help because what you're describing is impossible. It returning $nb gives you 3, returning (int)$nb would have to be 3 also.

            This code prints 3, even with the space in front of the 3.

            $nb = " 3";
            $total = (int)$nb;
            echo $total;


            This code also prints 3:

            $nb = " 3.1416";
            $total = (int)$nb;
            echo $total;
            [ed. note: BobRay last edited this post 10 years, 11 months ago.]
              • 42562
              • 1,145 Posts
              donshakespeare Reply #6, 11 years ago
              What is the type of input in the property set? Text or Intger?
                TinymceWrapper: Complete back/frontend content solution.
                Harden your MODX site by passwording your three main folders: core, manager, connectors and renaming your assets (thank me later!)
                5 ways to sniff / hack your own sites; even with renamed/hidden folders, burst them all up, to see how secure you are not.
                • 37909
                • 153 Posts
                :( I don't know. Sorry. How can I know that?
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  It says what it is.
                    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
                    • 37909
                    • 153 Posts
                    I don't know because it's the placeholder [[+total]] inside the chunk. Placeholder of Articles (same as getResources but in this case, obviously, it doen't work). And I put the placeholder inside a snippet call to calculate the half of the total. I'm clear?
                      • 28042 ☆ A M B ☆
                      • 24,524 Posts
                      Let's back up here. Start from the beginning. Where do you set the value of this? A TV for an Article resource?
                        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