We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28042 ☆ A M B ☆
    • 24,524 Posts
    What, exactly does a Static Resource use for its output? I have this code
    if($modx->resource->get('class_key') == 'modStaticResource') {
      $msource = $modx->resource->getTVValue('Source');
      $source = $modx->getObject('modMediaSource', $msource);
      $properties = $source->getProperties();
      $path = $properties['basePath']['value'];
      $content = $modx->resource->get('content');
      $path = $path . $content;
      $output = &$modx->resource->_output;
      $output = $path;
    }
    return;

    It does exactly what I expect it to do, it replaces the _output with the full path. But MODx doesn't use this value when processing Static Resources!

    My Media Source has "/var/www/dev/downloads/", and the content of the Static Resource is the rest of the path: "Documents/document1.pdf". The above code gets the Media Source basPath and the Static Resource's content, and concatinates them. The $output will return as "/var/www/dev/downloads/Documents/document1.pdf". However, MODx ends up with "/var/www/dev/public_html/Documents/document1.pdf". So it's just adding the site's base path to the Static Resources content, ignoring the modified _output.

    Static resources are processed in modresponse.class.php on line 181-182, after the OnWebPagePrerender event, and just before the document is flushed. So what is it using to process, and how can I modify it on the OnWebPagePrerender event?
      Studying MODX in the desert - http://sottwell.com
      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
      Join the Slack Community - http://modx.org
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      I tried modifying &$modx->resource->_content and it produced the same results. From what I can see, it runs process(), which immediately sets the _content and the _output to empty strings, it's getting the content from somewhere else. [ed. note: sottwell last edited this post 13 years ago.]
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 3749
        • 24,544 Posts
        If you use $modx->resource->getContent() instead of get('content'), you should get the processed content of the file. It happens in the modStaticResource class file. I'm not sure if that will help you, though.
          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
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          The problem is that the last thing the parser does is check if the resource is a modStaticResource and is binary. If so, it gets tossed back to process(), where the _content and _output are both emptied. I haven't been able to trace where it goes from that point.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org