We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 13218
    • 134 Posts
    Hi,
    i have a resource which builds a json object for some ajax action. for this the resource collects data from other resources, which generally works just fine. but in the process i need this resource to get another resources processed output. i’m doing it like this:
    $otherResource = $modx->getObject('modResource', $someID );
    $jsonObj['html'] = $otherResource->process();

    this actually does some processing, but it’s doing it wrong (at least not as i want it to).
    the other resource has a template kinda like this:
    <div id="no[[*id]]">[[*myTemplateVar]]</div>

    the *id gets filled with the id of the resource calling the process-method. the TV of course gets nothing. so, the data used for processing that other resource is the calling resource’s, not of the one that’s being called.

    so, my first question: is the process()-method the correct one or do i need to use something else?
    and secondly: if it’s correct, what am i doing wrong.

    thanks
    marc
      @itWilllBeOK
      • 13218
      • 134 Posts
      Just to be sure i added this:
      $otherResource = $modx->getObject('modResource', $someID );
      $jsonObj['html'] = $otherResource->process();
      $jsonObj['myTemplateVar'] = $otherResource->getTVValue('myTemplateVar');

      $jsonObj[’myTemplateVar’] actually has the correct value, the one from the resource being processed.
        @itWilllBeOK
        • 13218
        • 134 Posts
        ok, it actually seems to be a big deal to get a fully processed resource via the api:
        http://modxcms.com/forums/index.php/topic,52605.msg305325.html#msg305325

        using this:
        $jsonObj['html'] = file_get_contents($modx->makeUrl($someID,'','','full'));

        seems to be a little harsh when i have to get several resources per call. so i think i will change my process so that i can build all the resources in the calling script with chunks and snippet calls, as the are all fairly simple.
        something like getChunk or runSnippet would have been so nice, but it’s all good as it is...
          @itWilllBeOK
          • 3749
          • 24,544 Posts
          I agree. There should be an easy way to get the fully processed content field of a resource, IMO.
            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