On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • I’m working on a custom newsletter subscription addon for my church’s website. It consists of a module for sending the newsletter to everybody on the mailing list, and a snippet that the subscription page of the website uses for subscribing users.

    In the process of subscribing a new user, I need to send a few emails for confirmation, etc, so I’m using the excellent Swift Mailer library (http://swiftmailer.org/).

    To make it easy for the church staff to edit the text of these emails, I’m creating a document (unpublished) for each one, all organized into a subscriptions folder in the site tree.

    My question is, how can I get the parsed content of one of these documents in my snippet code so that I can pass it along to Swift Mailer to send the email? I will be setting some placeholders, so that’s the main reason I need to parse the content. Each email has the HTML message in the content field, but I also have a template variable that contains the plaintext version of the message, so it’d be great if I could get that parsed as well.

    If that’s not doable, then I could probably write my own code to replace the placeholders with the correct data, but it just makes more sense to use the built-in functionality of MODx to do so.

    Thanks!
      I'm learning more about MODx all the time and loving it.


    • There’s probably a much easier way, but I think you could use a TV with an @DOCUMENT binding. That should get you the unparsed content field of the document. Then pass that TV to a snippet that calls $modx->parseDocumentSource() to get the parsed result.

      To email Document 12, set the DocTv template variable to: @DOCUMENT 12

      Then, get the parsed content of document 12:

      [!GetParsedContent? &content=`[DocTV]' !]


      ?<
      //GetParsedContent snippet
      
      $output = $modx->parseDocumentSource($content);
      
      // do something with the parsed results here
      
      ?>
      


      I’m not sure this would process TV tags in the content correctly but it should handle everything else (if it works at all).

      TBH, if all you have to parse are placeholders, it would be much more efficient just to replace them yourself in a custom snippet. You could pass the document’s unparsed content to the snippet using an @DOCUMENT TV as above or with the GetField snippet, or, better, you could just pass the document’s ID to the snippet and have the snippet get the document directly with:
      $doc = $modx->getDocument(12, 'content', 1);





        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
      • I forgot to specify that this is with Evolution, and I believe parseDocumentSource() is only for Revolution, right?

        Anyways, as it turns out, I need to do my own placeholder replacing anyway, but the one thing that remains for me to need parsed content is that I don’t want to hardcode the URL to the page that a link in the email needs to point to. I’d like to use the standard [~187~] kind of thing in the document, and I need a way to replace that with the alias. Is that easily doable without parsing the whole page?
          I&#39;m learning more about MODx all the time and loving it.
        • Quote from: Compeek at Mar 05, 2010, 04:47 AM

          I forgot to specify that this is with Evolution, and I believe parseDocumentSource() is only for Revolution, right?

          Anyways, as it turns out, I need to do my own placeholder replacing anyway, but the one thing that remains for me to need parsed content is that I don’t want to hardcode the URL to the page that a link in the email needs to point to. I’d like to use the standard [~187~] kind of thing in the document, and I need a way to replace that with the alias. Is that easily doable without parsing the whole page?

          No, that’s Evo code. The whole thing would be *much* easier in Revo.

          $obj = $modx->getObject('modResource' array('id'=>$docID) ); 
          return $obj->process();


          The link tag will be replaced by a URL if the document is rendered, but if you’re getting the raw content, you could easily grab the ID from the tag, which you could then use to generate the URL with $modx->makeURL(). There’s no easier way that I know of.


            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
          • Thanks! That does what I need.

            As I’ve been thinking about this, I think it’d work just fine if I got the entire parsed document source (using it’s template and all, not just getting parsed [*content*]) since the email needs a full HTML document to be proper. For the plain text part, I could still just get the tv content and replace the URL tags myself.

            Is there any easy way that you know of to get the source of an entire parsed page? I would think that’d be simpler than trying to parse just the content, at least.
              I&#39;m learning more about MODx all the time and loving it.
            • I think you might be able to use a plugin listening for the OnWebPagePrerender SystemEvent: http://wiki.modxcms.com/index.php/API:Template_Service_Events#OnWebPagePrerender. It could check to see if a certain placeholder was set and, if so, email the page and send the user to another document without rendering the page.
                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
              • Hmm. Well, thanks much for your help, but I think I’m just going to stick with what I have then. On a Revolution site, like you said, this would be much easier, but right now I have code that makes the URLs for me, and Swift Mailer handles placeholders anyway (which I especially need for sending the same email with slight variations to different users).

                Thanks. laugh You’re always one of the first people to help me on here, and I really appreciate it.
                  I&#39;m learning more about MODx all the time and loving it.
                • Quote from: Compeek at Mar 05, 2010, 11:00 PM

                  Hmm. Well, thanks much for your help, but I think I’m just going to stick with what I have then. On a Revolution site, like you said, this would be much easier, but right now I have code that makes the URLs for me, and Swift Mailer handles placeholders anyway (which I especially need for sending the same email with slight variations to different users).

                  Thanks. laugh You’re always one of the first people to help me on here, and I really appreciate it.

                  Thanks for the kind words.

                  If it ain’t broke . . . wink
                    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
                  • Hello!

                    How parse string content modx REVO?

                    parseDocumentSource - is function on modx EVO

                    I have plugin, it compares the fields and if changed overwrites.
                    case 'OnBeforeDocFormSave':
                    /**code**/
                    if ($mode == 'upd'){
                        $oldRes = $modx->getObject('modResource', $data['id']);
                        $oldRes = $oldRes->toArray();
                       foreach ($fields as $field) {
                           if($oldRes[$field] != $data[$field] ){
                                 /**code**/
                                 if($field == 'content'){
                                     //$outoputContent = $modx->parseDocumentSource($data['content']);
                                     $modx->log(xPDO::LOG_LEVEL_ERROR, print_r($data,true));
                                  }
                                 /**code**/
                           }
                    }
                    

                    I need parse resource content and record other table. It's possible ?