We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37638
    • 63 Posts
    I have a snippet in a chunk that optionally sets a placeholder, and always returns an output. The placeholder should be set only if debug=1. However, instead of settings the placeholder it always just seems to print the debug info or output it with the rest (I'm not sure).

    Chunk code:
      [[mySnippet? &action=`someAction` &tpl=`pmcTpl` &sortby=`name` &debug=`1`]]
    
        <debug>
            [[+pcm.someAction.debug]]
        </debug>
    


    Relevant Snippet Code:
            if($this->properties['debug'] == 1 || $this->properties['debug'] === true){
                $this->modx->toPlaceholder("pcm.$action.debug", str_replace('`','',$this->debug));
            }
    


    I *expect* the output to be something like:
    Snippet output here...
    ...
    ...
    
    <debug>
    Debug output here...
    ...
    ...
    </debug>
    


    Instead, I get:
    Debug output here...
    ...
    ...
    
    Snippet output here...
    ...
    ...
    
    <debug>
    
    </debug>
    


    Am I misunderstanding how to use ->setPlaceholder?

    Revo 2.2.6

    This question has been answered by BobRay. See the first response.

    [ed. note: jmaddington2 last edited this post 13 years, 4 months ago.]
    • discuss.answer
      • 3749
      • 24,544 Posts
      On the face of it, what you're describing is impossible. wink

      Snippet output can only replace snippet tags and placeholder values can only replace placeholder tags.

      Are you sure there's not an 'echo' statement lurking around somewhere?

      You don't show the return statement of the snippet. Could the placeholder somehow be getting tacked onto the end of the return value (say, with a leftover .= operator)?

      Another possibility is that you're seeing a chunk or snippet return value that was cached before you changed the code.



        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
        • 37638
        • 63 Posts
        It is possible that there are some lurking echo statements (or something).

        I'll take your word at its being impossible, but if I may, how is what I am doing any different than using formIt -- where the snippet runs and then sets placeholders further down? I.e., http://rtfm.modx.com/display/ADDON/FormIt.Examples.Simple+Contact+Page
          • 3749
          • 24,544 Posts
          I may not have been clear. What you're trying to do makes perfect sense and is definitely possible. It's the results you're describing that are impossible without one of the other explanations I suggested.

            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
            • 18373 ☆ A M B ☆
            • 3,141 Posts
            You're not using something like
            $this->debug = print_r($vars)
            or
            $this->debug = var_dump($vars)
            are you? Both of those act like echo and would explain it showing up before the snippet output. if you are, you may want to try print_r($vars, true) instead - the second param makes it return the info as a string.
              Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

              Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
              • 37638
              • 63 Posts
              So, the issue was twofold:

              1. There were lurking $this->output .= ... that I had completely missed.

              2. $action was defined differently that I had remembered. After a good night's sleep I finally thought to check on that. So, basically, the snippet WAS filling in pcm.someAction.debug, but I had been calling with $action=someOtherAction.

              Thanks, both of you!