We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 11315
    • 32 Posts
    Okay, so what I’m trying to do is something like this:

    snippet #1

    content

    snippet #2

    which is simple enough. But snippet #2 needs information that snippet #1 generates. Is there any way to let snippet #2 have information from snippet #1? Or am I just basically screwed and there’s no chance of that ever happening?
      • 18397
      • 3,250 Posts
      Very easily done!

      The simplest way in my experience (although there are other ways) is to set a placeholder via this api command: http://modxcms.com/setplaceholder.html

      and then getting the value via either a paramater [+placeholdername+] in the snippet or via the http://modxcms.com/getplaceholder.html api command.
        • 11315
        • 32 Posts
        So do I use that by setting the placeholder in snippet 1 and then getting it in snippet 2? And if that is how it works, is that all there is to it?
          • 18397
          • 3,250 Posts
          Yes and Yes. There might be an easier way (globals?) but you’d have to ask Raymond or Jason about that (our code Guru’s)
            • 11315
            • 32 Posts
            Thank you sooo much!

            *goes off to try it out*
              • 11315
              • 32 Posts
              Actually still having a bit of a problem.. Where snippet #1 should be I get the error

              Parse error: parse error, unexpected T_STRING in /home/neolodge/public_html/dev/manager/includes/document.parser.class.inc.php(691) : eval()’d code on line 58

              and where snippet #2

              Parse error: parse error, unexpected T_STRING, expecting ’(’ in /home/neolodge/public_html/dev/manager/includes/document.parser.class.inc.php(691) : eval()’d code on line 3
                • 18397
                • 3,250 Posts
                That would be a syntax error. Are you sure your snippets are correct?

                If you are then check the api call. It should look like this:

                $modx->setPlaceholder($name,$value);
                
                  • 11315
                  • 32 Posts
                  Oh I didn’t know I needed the modx-> part in front.. I’ll try that now.
                    • 11315
                    • 32 Posts
                    Okay well now it looks like it’s almost working.. is there anything special I need to do if the thing I need to send is an array? Because now it’s looking like my error is because it is an array.
                      • 18397
                      • 3,250 Posts
                      I have no idea whether or not placeholders support arrays...

                      You can either try setting a global (no idea how that works) or turning your array into text and using an explode function in snippet 2 to turn it into an arrary.

                      The best thing to do is to have snippet 1 do all the work and output what snippet 2 should display as a placeholder. Then you could just do this:

                      [[snippet1]]

                      content

                      [+snippetoutput+]

                      which is alot cleaner and faster.