We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 9207 ☆ A M B ☆
    • 2,475 Posts
    Is there an accessible parsing function for MODx Revo? Like if I have a string full of placeholders and I want to replace them with values... the standard stuff.

    I can’t seem to find this anywhere. Even the $modx->getChunk() is somewhat obnoxious because it does too many things: it loads the chunk, AND parses it.
      • 9207 ☆ A M B ☆
      • 2,475 Posts
      This is the closest I’ve found: *process*:

      E.g. imagine loading a chunk, here with a primary key id of 40:

      $inputTpl = $modx->getObject('modChunk',40);
      return $inputTpl->process(array('name'=>'testing', 'i'=>5));


      You can use an object’s "process" method and pass it an associative array of keys=>values that will replace any instances of [[+placeholders]] in the loaded chunk.
        • 11155
        • 74 Posts
        By the way, is there any text editor/EDI with autocompletion for modx objects ?
          • 26903
          • 1,336 Posts
          Netbeans does this if you’ve set up your MODx install as a project.
            Use MODx, or the cat gets it!
            • 17499 ☆ A M B ☆
            • 872 Posts
            PhpStorm does it too.
              • 38162
              • 97 Posts
              UltraEdit and UES can be configured to support it. Although I would have expected them to add it out of the box, since they use MODx for their website. tongue
                • 18373 ☆ A M B ☆
                • 3,141 Posts
                Quote from: Everett at Nov 07, 2010, 10:37 PM

                Is there an accessible parsing function for MODx Revo? Like if I have a string full of placeholders and I want to replace them with values... the standard stuff.

                I can’t seem to find this anywhere. Even the $modx->getChunk() is somewhat obnoxious because it does too many things: it loads the chunk, AND parses it.


                $placeholders = array (
                 'phname1' => 'value',
                 'phname2' => 'value2',
                 'phname3' => 'last value');
                return $modx->getChunk($chunkname, $placeholders);
                  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.
                  • 9207 ☆ A M B ☆
                  • 2,475 Posts
                  Mark -- that one API function is the one that suffers because it loads the chunk AND parses it. There are many cases where I need to separate the two actions, e.g. maybe it’s not a chunk that I’m parsing. This was an irksome point in the Evo API, too.
                    • 18373 ☆ A M B ☆
                    • 3,141 Posts
                    What would be a case where you’d need to seperate getting the chunk, and parsing the placeholders?
                      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.
                      • 22303 MODX Staff
                      • 10,725 Posts
                      All of the parsing power is in the modParser class, but parsing in MODx is not a simple, one pass, one API call type endeavor. It requires recursive, multi-stage lexical analysis that is aware of caching and when to quit trying to parse placeholders and remove them.

                      If you look in the process() method of any modElement (or modTag) derivative class, you will see the part that applies to a single element. But the majority of the parsing process starts with the Resource and ends in modResponse::outputContent(). So it really depends on what you are trying to accomplish with the manual parsing.

                      That said, IMO, manual parsing should (and can) be avoided in most cases, but let’s explore your intentions here to see what the best solution is.