Revolution: Static resources not working correctly in 2.8.2

Created on 30 Apr 2021  路  5Comments  路  Source: modxcms/revolution

Bug report

Summary

When viewing a static resource (web context) in 2.8.2, only the content field renders. The rest of the template is ignored.
I noticed the issue when upgrading a site from 2.8.1 that relies on static resources.
As a quick fix, I have copied over modstaticresource.class.php from 2.8.1 and that works as expected.

Step to reproduce

Create an HTML file, create a static resource and link to the file. Be sure to use the new system settings resource_static_path or resource_static_allow_absolute. Assign a template that's not empty and has the [[*content]] tag specified.

Observed behavior

Only the content field renders. The rest of the template isn't there.
If the [[*content]] tag is removed from the template, then the template renders fine (obviously without the content).

Expected behavior

Template should render as normal with the static resource content being added via the [[*content]] tag.

Related issue(s)/PR(s)

Could be something to do with a change made here:
https://github.com/modxcms/revolution/pull/15656

Environment

MODX version 2.8.2

bug urgent

All 5 comments

@Mark-H Could you please check?

It looks to be an issue here:
https://github.com/modxcms/revolution/blob/2.x/core/model/modx/modstaticresource.class.php#L199-L205

If the content is returned then so is the template, fixing the issue:

// Output the content, either streaming with readfile() or by echo'ing content that was retrieved earlier from media source
if ($streamable) {
    if (!$contentType->get('binary')){
        return file_get_contents($file);
    } else {
        readfile($content);
    }
}
else {
    echo $content;
}

I'm not sure if that's the best way to handle it (pretty sure it's not since it's still considered streamable) but happy to do a PR if so.

Hi @muzzwood , I tested your solution and it seems working, thanks,
I didn't check eventually problems with the rest of the new code

Welp, I didn't know that was a way static resources could be used so that's a meatball i must've thrown out of the bowl of spaghetti this code was. 馃槀

This issue has been mentioned on MODX Community. There might be relevant details there:

https://community.modx.com/t/modx-2-8-2-tag-not-rendered-in-static-resources/3985/4

Was this page helpful?
0 / 5 - 0 ratings