How do I get the *unprocessed* value of a resources content field in a snippet?
I have to retrieve several content fields in an unprocessed/unrendered state as they have several modx tags in them that I need to run some regex on.
I have this, which works fine if I try to get the pagetitle, but errors if I try to get the content fields:
$children = $modx->getChildIds(2726);
$content = array();
foreach($children as $child){
$resource = $modx->getObject('modResource', $child);
if($resource){
$content[] = $resource->get('content');
}
}
echo '<pre>';
print_r($content);
echo '</pre>';
*** Not just websites, we also create signage, banners, print, trade show displays and more! ***
Sean Kimball CLP, CLS.
Technical Director / Sr. Developer | BigBlock Studios
._______________________________________________.
Bigblock Studios
http://www.bigblockstudios.ca Web site design & development.
27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
phone/fax: 905-426-5525
discuss.answer
Quote from: bennyb at May 24, 2013, 11:53 AMQuote from: sean69 at May 24, 2013, 11:17 AM
I have to retrieve several content fields in an unprocessed/unrendered state as they have several modx tags in them that I need to run some regex on.
I think getContent gets the raw unprocessed content of an element of a resources content field.
EDIT:
This should work:
sorry - no, it still returns the rendered content.
*** Not just websites, we also create signage, banners, print, trade show displays and more! ***
Sean Kimball CLP, CLS.
Technical Director / Sr. Developer | BigBlock Studios
._______________________________________________.
Bigblock Studios
http://www.bigblockstudios.ca Web site design & development.
27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
phone/fax: 905-426-5525
I think MODX is still processing the tags before you see the page, even with print_r.
Try this before the print_r():
$content = str_replace('[[', '[ [', $content);
[ed. note: BobRay last edited this post 13 years, 4 months ago.]
You can also get the unprocessed content in a plugin attached to OnParseDocument. It's in $content, which is a reference variable so if you change it, the changes get passed back before the page is rendered.
[update] Looking at the code, that may not work. You may have to use $modx->documentOutput, which is deprecated, but should still work.
Yes, getContent does work and yes, modx is just 'reprocessing' it on me
*** Not just websites, we also create signage, banners, print, trade show displays and more! ***
Sean Kimball CLP, CLS.
Technical Director / Sr. Developer | BigBlock Studios
._______________________________________________.
Bigblock Studios
http://www.bigblockstudios.ca Web site design & development.
27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
phone/fax: 905-426-5525