We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36805
    • 354 Posts
    Question

    How can I use the MODx API to fetch fully parser processed output into a variable? I have a page id and an instance of $modx standing by..

    Background info

    I developed a simple mailer which retrieves MODx documents published in the last 7 days.

    It loops through the results and makes emails in which subject=pagetitle and body=document content. I use the webuser email adresses as recipients and I send mails through swift library. The script is stored below public_html and is triggered weekly by a cronjob.

    The actual problem

    It works very nicely *but* the internal links in format [~283~] doesn’t get replaced. For now I’m not concerned with chunks and snippet output but the links must be valid. Otherwise there is not point to mailing a document.

    Edit : A semi-solution

    The documentparser puts it results into documentOutput which i can retrieve after calling executeParser. However it forces an echo and a buffer flush so there is some overhead but it works with this:
    define(PUBLIC_HTML, "public_html/"); // change according to webserver configuration
    require_once(PUBLIC_HTML.'manager/includes/config.inc.php');
    require_once(PUBLIC_HTML.'manager/includes/document.parser.class.inc.php');
    
    /* @var $modx DocumentParser */
    $modx = new DocumentParser();
    $_REQUEST['id'] = 175;
    $modx->executeParser(); // unfortunately this will not just set $modx->documentOutput but echo/flush it too
    $mymsg = $modx->documentOutput;
    
    echo "<br><hr><br>$mymsg"; // test if our variable contains the output

    Edit 2 :
    There is still the problem that the domain name will be missing from the urls. Unfortunately Tinymce config must be changed to store full urls, see http://modxcms.com/forums/index.php?topic=56352.0.
      • 36805
      • 354 Posts
      I ended up not calling the parser. Instead i retrieve the content from the database and use a call to $modx->rewriteUrls to properly build those urls.

      This is only a tiny part of the normal parsing flow. I’m fine without snippets and chunks so this solved my problem.