We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36755
    • 41 Posts
    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 but rendered as plain text only.

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

    ---

    This does not work:
    $docdata = $modx->getDocument(1234, 'content', 1);
    $output = $modx->parseDocumentSource($docdata['content']);
    $output = $modx->rewriteUrls($output);
    return $output;
      • 36755
      • 41 Posts
      Got the answer at https://stackoverflow.com/q/49206608/1066234

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

      return $out;