We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28042 ☆ A M B ☆
    • 24,524 Posts
    Then how could you use a placeholder as the argument for a snippet?

    [[MySnippet?value=[+placeholder+]]]
      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
      • 22303 MODX Staff
      • 10,725 Posts
      I think we have to have some sort of execution order rules. How bad would it be to say that snippets need to come before the placeholders they generate in the source order of the page? I don’t think that is a bad requirement; that’s how JS works, and it would improve performance by reducing the need to process the document recursively.
        • 24253
        • 125 Posts
        Yes, I think this is a good idea.

        If a placeholder can be placed before a snippet, and the snippet still has "access" to it....
        And what about name space collisions?

        [[@MySnippet?value=[[+placeholder]] ]]

        would work perfectly with the new parser....

          • 32963
          • 1,732 Posts
          Quote from: sottwell at Nov 17, 2005, 12:45 PM

          Then how could you use a placeholder as the argument for a snippet?

          [[MySnippet?value=[+placeholder+]]]

          Hmmm,

          To get that level of flexibility I think we can code the mergePlaceholder to replace placeholders that has a value assigned to it. If no value is assigned to the placeholder then that placeholder is stored inside an array for later processing.

          example #1:
          [[SnippetA]]
          [[SnippetB?param=[[+value]] ]]

          In the above SnippetA can pass a value to SnippetB via the "value" placeholder. This is because SnippetA will be executed before SnippetB and a value of would have then been assigned to "value" placeholder.

          example #2:
          [[SnippetB?param=[[+value]] ]]
          [[SnippetA]]

          In example #2 we reverse the order of execution. In this case SnippetB will be executed before SnippetA. This means that no value will be assigned to the "value" placeholder which means that "value" will only be processed (replaced) at the end of the loop.

          example #3:
          [[+MyCount]]
          [[CountValue]]
          [[+MyCount]]

          The [[CountValue]] snippet is used to increment the value of the "MyCount" placeholder. When the parser executes it will store the first "MyCount" placeholder for later processing. Next it will execute CountValue snippet which increments the "MyCount" placeholder. The next and finaly step is the process the second "MyCount" placeholder. At this time the parser will see a value for "MyCount" and replace it with the value.
          At the end of the loop the parser will then replace the first "MyCount" placeholder with the value set by CountValue.

          Does that make sense?


            xWisdom
            www.xwisdomhtml.com
            The fear of the Lord is the beginning of wisdom:
            MODx Co-Founder - Create and do more with less.