简体   繁体   中英

How to parse the document content and then process the final HTML within a snippet? (EVO2)

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, ie I get:

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

instead of

<p>...</p> <p>Nice snippet output. We calculated 12.</p> <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?

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM