On March 26, 2019 we launched new MODX Forums. Please join us at the new MODX Community Forums.
Subscribe: RSS
  • Hi,

    i want to render to a document manually to be able to send it via Email. I want the template to be applied to, so it should render the same way if invoked within a browser.

    I thought this would to it ($document is the correct document):
    $document->process();
    $document->_output = $document->_content;
    
    /* collect any uncached element tags in the content and process them */
    $modx->getParser();
    $maxIterations= intval($modx->getOption('parser_max_iterations', $options, 10));
    $modx->parser->processElementTags('', $document->_output, true, false, '[[', ']]', array(), $maxIterations);
    $modx->parser->processElementTags('', $document->_output, true, true, '[[', ']]', array(), $maxIterations);


    This is similar to what modResponse does, BUT somehow $document->process(); has a different result in my code than in the modResponse class. In the modResponse class the [[*content]] tag is correctly replaced while my manual call leaves it alone.

    Any ideas how to achieve a full manual document parsing or what step is missing in my code?
    • If some part of your resource would be enough, I would try to do it with getChunk() which processes all tags in that chunk.
      If you really need the full processed-page you can try to use fileGetContents().

      See also http://modxcms.com/forums/index.php?topic=52605.0
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
      • Thanks i know the file_get_contents resp. curl possibility but i would prefer another method. I also tried to "fake a request" with an output buffer but unfortunately the modResponse is flushig the output buffer.

        As far as your link is concerned it seems that there’s no solution. So maybe i have to try something else (like the getChunk method - in that case it would be nescessary to store the documents as chunks, right?). Could to the same with the template then by calling parseChunk with [[* as opening tag for the document identifiers. But this would require to create some chunks which isn’t a perfect solution at all.


        But one more thing to "normal" document processing: i can’t find the difference why the same method $document->process() does different things in my code and the modResponse code. So has anybody an idea how to get this working?

        • It's a pretty ugly method, but you could create a chunk with the content, save it, use getChunk(), and then delete the chunk.

          $resource = $modx->getObject('modResource', $id);
          $chunk = modx->newObject('modChunk', array ('name'=>'tempChunk'));
          $chunk->setContent($resource->getContent());
          $chunk->save();
          $myContent = $modx->getChunk('tempchunk');
          $chunk->remove();


          There really should be an easy way to get the fully processed content of a resource, but I don't know of one.

          [ed. note: BobRay last edited this post 2 years, 6 months ago.]
            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
          • It seems a bit crazy there isn’t a way to show the output of a document?!

            PS the code above returns

            Parse error: syntax error, unexpected T_OBJECT_OPERATOR
            • MODX Resources are view controllers responsible for building complete HTTP responses, dynamically. Reproducing everything the MODX request handling process does in a few lines of code is not possible. Resources are not pieces of reusable content, they are views. Summarizing simple pieces of Resources (static or dynamic without dependence on the Resource being requested) with getResources or Ditto is one thing, but trying to reproduce what the whole application is responsible for when routing and processing requests for a Resource is not a valid use case.

              FWIW, most web pages I’ve ever seen had to be modified to be used in HTML email anyway.
              • Quote from: BobRay at Mar 07, 2011, 04:40 PM
                It's a pretty ugly method, but you could create a chunk with the content, save it, use getChunk(), and then delete the chunk.

                $resource = $modx->getObject('modResource', $id);
                $chunk = modx->newObject('modChunk', array 'name'=>'tempChunk'));
                $chunk->setContent($resource->getContent());
                $chunk->save();
                $myContent = $modx->getChunk('tempchunk');
                $chunk->remove();


                There really should be an easy way to get the fully processed content of a resource, but I don't know of one.

                Second line corected:
                $chunk = $modx->newObject('modChunk', array('name'=>'tempChunk'));
                • @vhollo - Thanks. Fixed above. smiley
                    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