0

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.

Avatar
  • 14,622
  • 9
  • 119
  • 198

1 Answers1

0

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;
Avatar
  • 14,622
  • 9
  • 119
  • 198
  • Unfortunately, this does not work. The snippets in the loaded doc resource (content) appear still as plain text [!mysnippet!]. – Avatar Mar 10 '18 at 14:44
  • What does that do? How does it answer the question? Don't just blurt out code. Explain yourself! https://stackoverflow.com/help/how-to-answer – Rob Mar 10 '18 at 16:44