We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4266
    • 70 Posts
    Could we extend functionality of this snippet to show document’s summaries?
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Yes. Modify this line:

      $contentRow = $modx->getPageInfo($randomDocId,1,'content');


      The last argument can be a comma-separated list (all enclosed in the ’ ’); it will return an associative array of all the items you request in the argument.

      $contentRow = $modx->getPageInfo($randomDocId,1,'content, introtext');


      In this case, we should probably have the entire layout of the returned results generated by the snippet; this way you will have the necessary containers for positioning the various parts.

      // snippet RandomDoc
      // returns content from a random document 
      // from a given folder
      // usage [!RandomDoc?folder=`xxx`!]
      // if $folder is not set, uses current doc ID as folder
      $folder = isset($folder)?$folder:$modx->documentIdentifier;
      $docs = $modx->getActiveChildren($folder);
      // get a random document id
      $rnd = rand(1, count($docs));
      $rnd -=1; // because we need to start at 0 in the array
      $randomDocId = $docs[$rnd]['id'];
      // get the content of the random doc
      $contentRow = $modx->getPageInfo($randomDocId,1,'content, introtext');
      $ret = '<div id="content">'.$contentRow['content'].'</div>';
      $ret .= '<div id="introtext">'.$contentRow['introtext'].'</div>';
      return $ret;


      (thinking rude thoughts about whatever genius called this field "introtext" in the database, but "summary" in the document settings form >:( )
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 4266
        • 70 Posts
        Thank you again for your clear explanation smiley
          • 7455
          • 2,204 Posts
          OK with the use of a template and the showdoc snippet i managed to get me a random homepage on www.eljakim.nu

          here is the snippet ( a little altert version i only wanted the id not the content):

          // snippet RandomDoc
          // returns id numbers from documents
          // from a given folder
          // usage [!RandomDoc?folder=`xxx`!]
          // if $folder is not set, uses current doc ID as folder
          $folder = isset($folder)?$folder:$modx->documentIdentifier;
          $docs = $modx->getActiveChildren($folder);
          // get a random document id
          $rnd = rand(1, count($docs));
          $rnd -=1; // because we need to start at 0 in the array
          $randomDocId = $docs[$rnd]['id'];
          return $randomDocId;
          


          and here the template code:

          <html>
          <head>
          <title>Eljakiekje</title>
          </head>
          
          <body onLoad="document.form1.submit()">
          <form name="form1" method="post" action="[~[!RandomDoc?folder=`14`!]~]">
          </form>
          </body>
          </html>
          


          this way it wil open a new page every time

          Thanks a lot for the help

          Greets Dimmy
            follow me on twitter: @dimmy01
            • 12561
            • 7 Posts
            Cheers guys, I also find this quite useful.

            But how did you use ShowDoc to display 3 random documents?

            And by that I mean showing parts of 3 random documents (under a folder) on the homepage.
              • 7455
              • 2,204 Posts
              Quote from: iamrick at Feb 19, 2006, 04:26 PM

              Cheers guys, I also find this quite useful.

              But how did you use ShowDoc to display 3 random documents?

              And by that I mean showing parts of 3 random documents (under a folder) on the homepage.

              I made 3 documents that have a template like the "normal template"so i did not insert only parts of that document but just placed a compleet new document taken form a folder random

              the homepage template is like i showed above its just a pice of script that reloads the homepage with a random document from a folder using the random doc snippet (adapted so it only returns a doc id).

              Greets Dimmy

              Greets Dim
                follow me on twitter: @dimmy01