简体   繁体   中英

Load Resource content of other document into recent document and execute its snippets - Evolution CMS (former ModX Evo)

I like to use a snippet (that I place in document A) to load content of document B and display it.

If it would be only HTML, it would be easy to load like that using the snippet:

$docdata = $modx->getDocument($docid, 'content', 1);
return $docdata['content'];

However, the document resource loaded contains snippets itself. And those will not be executed like this.

How can I: 1. load the content and 2. force the execution of the snippets thereafter.


PS for Mods: I have introduced the new tag evolution-cms for this post, since modx evo is continued with this new name at evo.im . See also Github .

This should work:

$docdata = $modx->getDocument($docid, 'content', 1);
$out = str_replace(array('[!', '!]'), array('[[', ']]'), $docdata['content']);
$out = $modx->parseDocumentSource($out);
$out = $modx->rewriteUrls($out);

return $out;

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