Jump to main content Jump to doc navigation

In some cases you'll need to parse snippet, chunk or lexicon tags outside of the regular parsing flow. For example when generating email content, or when building an API that needs to return fully-processed content.

When doing so, you may notice that modX::getChunk only processes regular [[+placeholders]], and not all other valid tags contained in the chunk.

In those cases, you can use the modParser to complete processing:

// First render a chunk, which processes the provided placeholders
$content = $modx->getChunk('MyChunkName', ['foo' => 'bar']);

// Get the modParser instance
$parser = $modx->getParser();

// Define how deep we can go
$maxIterations= (integer) $modx->getOption('parser_max_iterations', null, 10);

// Parse cached tags, while leaving unprocessed tags in place
$parser->processElementTags('', $content, false, false, '[[', ']]', [], $maxIterations);
// Parse uncached tags and remove anything that could not be processed
$parser->processElementTags('', $content, true, true, '[[', ']]', [], $maxIterations);

return $content;

Support the team building MODX with a monthly donation.

The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.

Backers

  • modmore
  • STERC
  • Digital Penguin
  • Jens Wittmann – Gestaltung & Entwicklung
  • Fabian Christen
  • Dannevang Digital
  • Sepia River Studios
  • Chris Fickling
  • CrewMark
  • deJaya
  • Lefthandmedia
  • Murray Wood
  • eydolan
  • Following Sea
  • Anton Tarasov
  • Stéphane Jäggi
  • Raffy
  • Snow Creative
  • A. Moreno
  • Nick Clark
  • JT Skaggs
  • Helen
  • YJ
  • krisznet
  • Richard
  • Yanni

Budget

$301 per month—let's make that $500!

Learn more