We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 727
    • 502 Posts
    I’m probably being a bit thick here, but I’ve searched and can’t find an answer...

    I have a snippet that returns the content of a specific document:

    $doc = $modx->getDocument($docid);
    return $doc['content'];


    However snippet calls in the document are not parsed. Which API call do I need to make to get the parsed document content?

    Andy
      • 21496
      • 225 Posts
      There’s a snippet called DynContent doing it like this:

      <?php
      $docid = isset($docid) ? $docid : "";
      if(empty($docid)) return "";
      $doc = $modx->getDocumentObject('id',$docid);
      $output = str_replace(array("[!","!]"),array(""),$doc['content']); ;
      return $modx->parseDocumentSource($output);
      ?>
      


      Does that help you?
        René
        • 727
        • 502 Posts
        Thanks, that’s what I needed to send me down the right path.

        The code posted doesn’t work for uncached snippets, because it seems parseDocumentOutput only works on cached snippets. If you look at line 437 in the document parser in 0.9.6.1 you will see:

        $this->documentOutput= str_replace('[!', '[[', $this->documentOutput);
        $this->documentOutput= str_replace('!]', ']]', $this->documentOutput);
        
        // Parse document source
        $this->documentOutput= $this->parseDocumentSource($this->documentOutput);


        I changed it to this and my uncached snippet is now parsed.

        Andy
          • 7231
          • 4,205 Posts
          How does parseDocumentSource differ from getDocument? I was unable to find any docs on parseDocumentSource.

          From what I could tell it goes one step beyond getDocument by running it through the parser whereas getDocument gets the raw data. Is this correct?
            [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

            Something is happening here, but you don&#39;t know what it is.
            Do you, Mr. Jones? - [bob dylan]
            • 727
            • 502 Posts
            That is my experience of using those functions.

            parseDocumentSource has some comments on it’s functionality in the document parser source code.

            Andy