Does $modx->parseDocumentSource() still work? Using it makes page rendering fail, but no errors are recorded. I need to process tags inside a field (not the content field) inside PHP.
I don’t think that method exists any more (which would explain why your page doesn’t work).
Can you give more detail about what you’re trying to do (which fields? what kind of tags?).
For most simple use cases, you can create a (temporary) chunk object and then parse it.
This should work for placeholders and snippet calls.
MODX 3 sample code:
<?php
use MODX\Revolution\modChunk;
$content = '... [[+my_placeholder]] [[someSnippetCall]] ...';
$phs = ['my_placeholder' => 'placeholder value'];
$chunk = $modx->newObject(modChunk::class, ['name' => 'inline-' . uniqid()]);
$chunk->setCacheable(false);
$parsed_content = $chunk->process($phs, $content);
return $parsed_content;
I have a placeholder tag in the longtitle field in a conference site (e.g., [[+day2]]. The tag pulls a date for the particular day of the conference, formatted as month, day, and year. But I need to strip the year off the end of that date for a certain place in the agenda. It would be easy to do that if PHP could get the rendered output of the placeholder tag.
For now, I’ve gotten around that by stripping out the characters ‘[’, ‘]’, and ‘+’ from the longtitle field content and then running $modx->getPlaceholder() on the result of that conversion. But it would be nice to be able to just get rendered content directly because that would work for all types of tags.
That’s a clever idea. Didn’t know you could create temporary chunks. Not very direct, but I could just make a function out of that and use it where needed. Thanks!