We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • I have a resource using a template BLOCK-TPL which contains many TVs to describe a block of content. It may be a static content or a dynamic content which will be updated from other Document (by using document ID).

    Currently I want to get processed (rendered) resource (which is using BLOCK-TPL) (include template rendered, TVs processed), is there a way to do that by MODx API or pure php code if possible?
    Before getting to this question, I made those things worked by using ajax loading to load processed resources, but that solution is not really efficient, it's causing my home page (included many blocks) have a bottle-neck and too many concurrent connection s to shared hosting server is a bad deal.
      • 3749
      • 24,544 Posts
      It depends on where you are when the code executes. It's very difficult to get a fully rendered resource in code.

      You should be able to get it anywhere, though, with cURL by just requesting the page, though it won't be blindingly fast.

      EmailResource does it by having a plugin connected to OnWebPagePrerender and executing when the user previews the doc from the Manager.


      ---------------------------------------------------------------------------------------------------------------
      PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
      MODX info for everyone: http://bobsguides.com/modx.html
        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
      • Hi Bob,
        I want to use those code in other Template as my homepage. I just want to catch the index.php?id=ID by pure php code or MODx API. Using jquery ajax load seems fine for me, but some complain from other user, some blocks are not shown because of the limitation shared hosting concurrent connection.
        I also have a though about using cURL, but I dont really whether it will be different from using ajax loading.
        I wonder where a api function for call processed resource, e.g: $modx->resource->getObject() ?
          • 3749
          • 24,544 Posts
          Unfortunately, getting the resource object will get you the unparsed code of the page with no template. AFAIK, there's no simple method for parsing it completely.

          If you just want the *content* field, you can use getResourceField, but I can't remember if the result is parsed or not. I suspect not.

          I think that cURL would have the same result as the Ajax call. The problem there is really a server problem. I think I'd either ask the host to raise the limit on concurrent connections or change hosts.


          ---------------------------------------------------------------------------------------------------------------
          PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
          MODX info for everyone: http://bobsguides.com/modx.html
            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
          • This has been asked for many times, and I have finally obliged, despite the risks and issues with doing this.

            renderResources will provide the complete output of a collection of Resources is a similar manner to getResources. The only real difference is that you are rendering the complete output of the Resource using it's Template, rather than recombining properties of the Resource in a Chunk tpl. In renderResources, the tpl's serve simply as a wrapper for the complete output and are not at all necessary.

            Some initial documentation at http://rtfm.modx.com/display/ADDON/renderResources — enjoy, but remember this is experimental and may not work for you in all cases. In particular note that you cannot use this with Resources having a binary Content Type, WebLinks, or SymLinks. Currently, it will only work with modDocument and modStaticResource classes, but we may be able to expand support for other Resource classes including CRCs in the future.

            Feedback appreciated.
            • Um, my blocks are just interfaces (somehow like that) to obtain data from other containter resources. And yes, they're modDocument. I'll post feedback after digging to this. Thank you million times, Bob and Opengeek.
                • 8898
                • 181 Posts
                Hello Jason,

                could you be a little bit more explicit regarding the "risks and issues"?

                An employment agency wants to be able to upload the job offers to several portals (like Monster) as complete HTML files. So in the MODX Manager I'm offering the files for download. In a plugin, I'm calling renderResources for the current resource ID, and I'm indeed getting the HTML code that I can then modify before offering it for download. But the HTML code is not complete - the main menu is missing (it's generated by a Wayfinder call).

                It's not really a problem in this context as I'd eliminate the menu anyway, but I'd really like to know why this is happening.

                The body of the template begins with

                <body>
                    <div class="ym-wrapper">
                        <div class="ym-wbox">
                
                            [[$MainMenu]]
                            [[$PageHeader]]
                
                            <div class="mainContainer">
                                <div class="ym-column">
                

                Everything can be found in the generated HTML code, including the page header, but, as mentioned before, the main menu is missing. The MainMenu chunk looks like this:

                [[!Wayfinder?
                    &startId=`0`
                    &level=`2`
                    &where=`[{"id:<=":7},{"OR:parent:>":0,"AND:parent:<=":7}]`
                    &hideSubMenus=`0`
                    &cacheResults=`1`
                    &titleOfLinks=`description`
                    &sortBy=`menuindex`
                    &outerTpl=`menuOuterList`
                    &innerTpl=`menuInnerList`
                    &rowTpl=`menuItem`
                    &hereTpl=`menuItemCurrent`
                    &innerRowTpl=`subMenuItem`
                    &innerHereTpl=`subMenuItemCurrent`
                    &outerClass=`megamenu`
                    &innerClass=`dropdown_fullwidth`
                    &rowClass=`menuItem`
                    &levelClass=`navLevel`
                    &parentClass=`isSubmenu megamenu_drop`
                    &firstClass=`firstMenuItem`
                    &lastClass=`lastMenuItem`
                    &hereClass=`menuItemOpen`
                    &selfClass=`menuItemActive`
                    &webLinkClass=`isWeblink`
                ]]

                The outer template (menuOuterList) contains the following lines:

                <!-- Start main (top) navigation -->
                <nav id="mainNav" class="ym-hlist megamenu_container megamenu_light_bar megamenu_light">
                    <a href="/" id="logoLink"><img src="assets/images/design/logo-400x58.png" width="400" height="58" alt="Logo" /></a>
                    <ul[[+wf.classes]] id="navigation">
                [[+wf.wrapper]]    </ul>
                </nav>
                <!-- End main (top) navigation -->

                The menu works perfectly when the normal page is displayed, but there's no hint of it in the code generated by renderResources.

                Any ideas?

                Cheers,
                Jan [ed. note: enigmatic_user last edited this post 10 years, 7 months ago.]
                  This message has been ROT-13 encrypted twice for higher security.