Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
157 views
in Technique[技术] by (71.8m points)

php - 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, 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 EvolutionCMSCore::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?

question from:https://stackoverflow.com/questions/65602321/how-to-parse-the-document-content-and-then-process-the-final-html-within-a-snipp

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...