We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • I’m trying to get the processed html of a page with:

    <?php
    $doc = $this->modx->getObject('modResource', 1);
    $message = $doc->process();
    ?>
    


    But for some reason $message still contains all the template codes (like [[*content]]) instead of the processed page. What did I do wrong?
      Jeroen Kenters

      MODX Professional | MODX Ambassador | Dutch MODX forums moderator

      website | twitter
      • 3749
      • 24,544 Posts
      Try switching the cacheable checkbox for the resource, saving it, and clearing the site cache.
        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
      • That is not the same as processing all of the output. To generate the complete output of a page in MODx requires several steps, because first all cacheable tags are processed and returned with non-cacheable tags untouched. Then that is run through the process, this time without ignoring non-cacheable tags. Finally, one more pass attempts to process anything leftover and removes any tags that are at the end.

        See the modResponse::outputContent() method for the complete implementation of the process following the processing of a modResource instance with the process() method.
          • 3749
          • 24,544 Posts
          Since we have other methods to get the processed output of chunks, snippets, and TVs and $resource->process() is impractical, does $object->process() have any practical public uses?
            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
          • Yes, to process properties, filters, non-cacheable output, and everything else it is responsible for. It’s not at all impractical.
              • 3749
              • 24,544 Posts
              Sorry, I wasn’t clear. The key word was "public." I didn’t mean to suggest that it was impractical at all.

              I just meant that I don’t see much use for it on the part of the average user, who can use getChunk(), runSnippet() and getTemplateVarOutput() and who would probably not want a version of the content field of a resource that might, or might not, be fully processed.

              BTW, is there a convenient way to get the fully processed content field of a resource? I can’t think of one.
              If not, should there be one?
                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
              • For now I get the fully processed page (I need the full page, not just the contents) by using PHP’s file_get_contents(’url_to_resource’). It works, but I can’t actually call this an elegant solution. smiley
                  Jeroen Kenters

                  MODX Professional | MODX Ambassador | Dutch MODX forums moderator

                  website | twitter
                • TBH, that is the proper way to get the whole Resource; the whole purpose of a Resource is to represent a fully requested and rendered web page, and that is how you would have to get any other web page that is dynamically or statically generated. MODx has to register javascripts and CSS, deal with serving very large files that have to be buffered directly to the browser, etc. There is no way to reduce this to some simple formula of how to render all the dynamic portions of the Resource programmatically. This is why summaries and abstracts are created, and why automatic thumbnails don’t always choose the right part of a photo to crop. Elements, not Resources, are really meant to be the reusable pieces of static and dynamic content that should be able to appear on various Resources throughout a site.

                  That said, I’ve described how to go about rendering basic Resources with non-cacheable tags. Feel free to author some components that address this in ways appropriate to the specific problems at hand. Or you can request this as a feature in getResources and I’ll be happy to work on this when I get a chance.
                    • 25506
                    • 6 Posts
                    I’m trying to do something similar: I want to have a snippet loop through the children of a selected resource and export the rendered HTML of each of those children. I’d like to avoid PHP’s file_get_contents() because that could get pretty slow if the loop contains more than just a few children.

                    However, I’m having trouble working out which bits of modResponse::outputContent() I need, and in what order. It looks like process() gets called first, and then processElementTags() gets called twice on the parser. I’ve tried various things, and the best output I’ve managed to get is the processed resource, but minus any TVs - which is the same result I get if I just use $resource->process().

                    Do you have a sample bit of code to demonstrate how what calls are needed in a snippet to get a rendered page (by id)?
                      • 17016
                      • 138 Posts
                      Is it also possible to process the resource by an other template than defined in the resource by using these technique or is this not possible?

                      Letti