2

In Evolution CMS (former MODx Evolution) I have some scenarios where I use a snippet to go through the document content using the DOM in PHP.

The document content contains HTML and several snippets. Those snippets generate custom HTML output (when rendering for frontend).

Now I need this final HTML output (inside the executing snippet) when using the DOM.

If I do it with my snippet, the output of the other snippets is not processed, i. e. I get:

<p>...</p> [[snippetx]]

instead of

<p>...</p> <p>Nice snippet output. We calculated 12.</p>.


I have tried the following code without success where I try to execute the rendering:

// public function renderDoc($id, $events = false, $tpl = null)
$docid = 123;
$events = false;
$tmplid = 1;

$output = $modx->renderDoc($docid, true, $tmplid);
return $output;

This returns NULL in EVO 1.4.

I have updated to EVO2. Now there is the error message:

Error : The EvolutionCMS\Core::renderDoc() method is undefined

Seems there is another method for rendering the content now.

So how to parse the content first to HTML to process it safely afterwards with the snippet?

Avatar
  • 14,622
  • 9
  • 119
  • 198
  • No [mcve] = no answers. This question won't benefit from a bounty; it will benefit from becoming Clear by providing sample input. – mickmackusa Jan 12 '21 at 14:12
  • How can I integrate an entire CMS into a jsfiddle. That's just not possible. Everyone who is familiar with this CMS understands the question. – Avatar Jan 12 '21 at 21:54
  • How can we reproduce the issue without sample input that gives your undesired output? – mickmackusa Jan 12 '21 at 22:56

1 Answers1

1

Answering the question:

// parse any snippets in document $content
// need to replace brackets to be able to parse snippets
$content = str_replace(array('[!', '!]'), array('[[', ']]'), $content);
$content = $modx->evalSnippets($content);
Avatar
  • 14,622
  • 9
  • 119
  • 198