Retrieving raw content with pdoTools or getResources?

Hi,
I’m trying to create a custom JSON feed and display raw content from resources (no parsing).

I want the content exactly as stored in TinyMCE, without MODX parsing anything.

For example, a chunk like [[$onetwothree]] should remain [[$onetwothree]].

I want it to stay exactly like that in the JSON, not rendered.


I tried:

  • pdoResources → chunks are executed
  • pdoFetch → same result
  • different tpl / INLINE → same

Is there a way to get the raw content (before MODX parser runs)?

Or is it just not possible with pdoTools / getResources?

Thanks

This in a snippet should work. It escapes the opening brackets so that MODX doesn’t try to parse the result.

<?php
$resource = $modx->getObject('modResource', [[+resource_id]]);

if ($resource) {
    $content = $resource->get('content');
    $escapedContent = str_replace('[[', '&#91;&#91;', $content);
    
    return $escapedContent;
}

Generally, everything that gets returned by a MODX resource is parsed by the MODX parser. It’s just part of the normal processing sequence.

To get the raw values, I would either use a MODX REST API or create a custom file that loads MODX externally and returns the JSON.

If you really need to use a MODX resource, I guess you have to prematurely terminate the processing directly in your snippet to make it work (which is a bit hacky). Something like this:

...
header("Content-Type:text/xml");
@session_write_close();
exit(json_encode($data));

Thanks @dev_willis and @halftrainedharry, your replies put me on the right path :smiling_face:

In the end I went with a custom snippet using pdoFetch to build a JSON feed directly. Works perfectly :+1: